[Answer]-How to deal with many-to-many in django / tastypie

1👍

Not sure what issues you are having, but you should add primary keys to each model, typically an auto int field.

class Blueprint(models.Model):
    id = models.AutoField(primary_key=True)
    name = models.CharField(max_length=120)
    description = models.TextField()

    class Meta:
        ordering = ["name", ]


class Workload(models.Model):
    id = models.AutoField(primary_key=True)
    blueprints = models.ManyToManyField('Blueprint', db_constraint=False)
    name = models.CharField(max_length=120)
    description = models.TextField()
    image = models.CharField(max_length=120)
    flavor = models.CharField(max_length=120)

    class Meta:
        ordering = ["name", ]

You should be able to create a blueprint without a workload. However, with current syntax you Can Not have a workload without a blueprint assigned. If you want to allow workloads with no blueprint, then add null=True, blank=True to that field.

as for the url; there is tons of posts on here that show how to setup a url like your asking.

Leave a comment