having an ManyToMany field, and have it optional

1,704 views
Skip to first unread message

kamilski81

unread,
Feb 10, 2010, 10:18:44 PM2/10/10
to Django users
Is it possible to do:

class GoalTag(models.Model):
goals = models.ManyToManyField(Goal, null=True)

The reason why i ask is that a goal can have many tags, and a tag can
belong to many goals. However, after a tag is input and a user
deletes a goal, the tag should still remain in the databse.

Currently i'm running into issues, and the 'goal' field is required
when I am inputting a tag...can i change this?

Thanks in advance

Atamert Ölçgen

unread,
Feb 11, 2010, 1:20:36 AM2/11/10
to django...@googlegroups.com
On Thursday 11 February 2010 05:18:44 kamilski81 wrote:
> Is it possible to do:
>
> class GoalTag(models.Model):
> goals = models.ManyToManyField(Goal, null=True)
Try blank=True. That null=True is possibly redundant there.


--
Saygılarımla,
Atamert Ölçgen

-+-
--+
+++

www.muhuk.com
mu...@jabber.org

iliveinapark

unread,
Feb 11, 2010, 1:26:10 AM2/11/10
to Django users
Both are required for a ForeignKey or ManyToManyField to be empty, ie:

class GoalTag(models.Model):
goals = models.ManyToManyField(Goal, blank=True, null=True,)

Atamert Ölçgen

unread,
Feb 11, 2010, 4:16:21 AM2/11/10
to django...@googlegroups.com
On Thursday 11 February 2010 08:26:10 iliveinapark wrote:
> Both are required for a ForeignKey or ManyToManyField to be empty, ie:
>
> class GoalTag(models.Model):
> goals = models.ManyToManyField(Goal, blank=True, null=True,)
That is not true. Check contrib apps for examples.

iliveinapark

unread,
Feb 11, 2010, 5:08:38 PM2/11/10
to Django users
I guess you're correct Atamert, though I'm sure this is still the case
for ForeignKey fields, isn't it?
Reply all
Reply to author
Forward
0 new messages