newforms: saving relations via intermediary table

0 views
Skip to first unread message

va:patrick.kranzlmueller

unread,
Jul 5, 2007, 9:44:08 AM7/5/07
to django...@googlegroups.com
I´m having trouble using newforms with an intermediary table
(although I´m not sure that my problem relates to newforms anyhow).

models:
class UserExtendedProfile(models.Model):
...
class UserExtendedProfileFavourites(models.Model):
userextendedprofile = models.ForeignKey(UserExtendedProfile,
edit_inline=models.TABULAR, num_in_admin=5, max_num_in_admin=5,
num_extra_on_change=1)
...

views:
...
user_extended_profile.save()
# set favourites
user_extended_profile.userextendedprofilefavourites_set = [fav1,
fav2, fav3]

now, when saving the related favourites, the _old_ favourites are not
deleted but the new ones are added.
I thought it´s possible to update the favourites in a way that the
old ones are deleted and the new ones are added. Am I wrong with my
assumption or do I use the wrong code?

thanks,
patrick


va:patrick.kranzlmueller

unread,
Jul 5, 2007, 11:38:30 AM7/5/07
to django...@googlegroups.com
solution:
user_extended_profile.userextendedprofilefavourites_set.all().delete()
before inserting the new related object works.
Reply all
Reply to author
Forward
0 new messages