#17253: Add foreign object in memory without saving to database
----------------------------------------------+--------------------
Reporter: cyberkoa@… | Owner: nobody
Type: New feature | Status: new
Component: Database layer (models, ORM) | Version: 1.3
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Easy pickings: 0 | UI/UX: 0
----------------------------------------------+--------------------
Similar to the following post
http://stackoverflow.com/questions/7908349/django-making-relationships-in-
memory-without-saving-to-db?answertab=active#tab-top
class Group:
name = models.Chars()
def save():
super(self, Group).save()
# access foreign objects
members = self.groupmember_set.all()
class GroupMember:
group = models.ForeignKey(Group)
member = modesl.ForeignKey(User)
I have a page to allow people to create Group , and invited existing user
to become member.
When form is submitted, Group data and GroupMember data is submitted
together.
I would like to override the Group's save function() , and in the save
function(), I need to access the GroupMember data.
Example code
g = Group(name='abc')
gm1 = GroupMember(member=user1, group=g)
gm2 = GroupMember(member=user2, group=g)
g.groupmember_set.add(gm1) # Add to memory , I do not want to save to db
immediately
g.groupmember_set.add(gm2) # Add to memory , I do not want to save to db
immediately
g.save()
gm1.save()
gm2.save()
Since the .add() function save the related object to db immediately ,
causing error.
I do not want to save the Group object first , because it will trigger 2
times save()
--
Ticket URL: <https://code.djangoproject.com/ticket/17253>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/django-updates?hl=en.