On Fri, May 15, 2009 at 12:04 PM, aa56280 <aa56...@gmail.com> wrote:

>
> I'm trying to wrap my head around why a ForeignKey needs to be set
> with null=True in order for its related model to call remove() on one
> of its instances.
>
> For example:
>
> # models
> class Company(models.Model):
>    ...
> class Location(models.Model):
>    ...
>    company= models.ForeignKey(Company)
>
>
> # view
> company = Company.objects.get(pk=1)
> location = Location.objects.get(pk=1)
> company.location_set.remove(location)  # raises 'RelatedManager'
> object has no attribute 'remove'
>
> Any help is appreciated as I can't find much documentation on this.
>
>
>
> >
>
Because the way to remove an object from a related set is to set the foreign
key to None, so it no longer refers to it, however if the foreign key isn't
nullable the only option is to actually delete the object, which isn't
exactly the same as what you specifified (since its destructive).

Alex

-- 
"I disapprove of what you say, but I will defend to the death your right to
say it." --Voltaire
"The people's good is the highest law."--Cicero

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to