开发者

ManyToManyField using Through and blank=True still required in admin interface

开发者 https://www.devze.com 2023-01-30 05:45 出处:网络
My model (partial code): class Observation(models.Model): date = models.DateField() geom = models.PointField()

My model (partial code):

class Observation(models.Model):
    date = models.DateField()
    geom = models.PointField()
    values = models.ManyToManyField(Label, through='Value', null=Tr开发者_JS百科ue, blank=True)
    objects = models.GeoManager()


class Value(models.Model):
    observation = models.ForeignKey(Observation)
    label = models.ForeignKey(Label)
    value = models.CharField(max_length=100)
    objects = models.GeoManager()

When I manage an Observation object in the admin interface, it still says at least one value per observation is required.

Am I doing something wrong, is this a bug, or should I write a derived Admin class to solve this?


I solved this by improving my ERM. The field values in Observation is obsolete, since you get a value_set from the ForeignKey relation in Value.

Still a weird side effect, but since there were no replies I'll consider it something that doesn't occur often.


This is happened to me too.

How exactly you got it resolved?

Following modification seems to do the trick: But not sure, what effect it's having at DB level.

class Value(models.Model):
    label = models.ForeignKey(Label, blank=True, null=True)
0

精彩评论

暂无评论...
验证码 换一张
取 消