I come from the world of Java and Hibernate and trying to get familiar
with Django (loving it by the way). The issue I am running into is the
relationship setup between the model classes and there related
objects. For instance say i have:
class Blog(models.Model):
   name = models.CharField()

class Entry(models.Model)
     name = models.CharField()
     blog = models.ForeignKey(Blog, related_name="entries")

I would love to be able to create this:

blog = new Blog(name="Test blog")
entry = new Entry()
entry.name = "Entry 1"
entry.blog = blog

and then be able to pass blog and around to different functions or
views and still be able to access the entries tied to it without
having to save the blog object first (there may be business logic that
does things to blog first before it is finally saved). Using it this
way blog.entries was empty because I believe I have not saved it yet
and blog.entries.add(entry) through a constraint error because the
entry.blog_id value did not exist in the blog table again because I
have not saved it yet.

In hibernate I could do this because the ORM treated the objects just
like POJOs and I mught have to do a little extra lifting to make sure
the save went ok. I am wondering if the Django ORM has the same type
on construct built into it so I can use my model classes like POPOs
until I need to persist?

Thanks for any help,
Travis

--~--~---------~--~----~------------~-------~--~----~
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