Use either
--------
e = Subgroup.objects.get(subGroupName="p1sub1")
e.save()
m = User(name="xxx", subGroup=e)
m.save()
--------
or
--------
e = Subgroup.objects.get(subGroupName="p1sub1")
e.save()
e.user_set.create(name="xxx")
--------
or
--------
e = Subgroup.objects.get(subGroupName="p1sub1")
e.save()
m = User(name="xxx")
m.save()
e.user_set.add(m)
--------

Good luck!
Aidas Bendoraitis [aka Archatas]



On 11/8/06, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
>
> I know this maybe very simple, but I can't find the answers on the net,
> I'm using following method to create object with ForeignKey, this
> however works,
> but according to django document you should avoid using "_id"  column,
> what's the correct way to do this? any idea? (running django 0.95)
>
> =====
> in shell/view:
>
> m = User()
> e = Subgroup.objects.get(subGroupName="p1sub1")
>
> m.name="xxx"
> m.subGroup_id=e.subGroupName
> m.save()
>
> =====
> model.py:
>
> class User(models.Model):
>         name = models.CharField(maxlength=255,primary_key=True)
>         subGroup = models.ForeignKey('Subgroup')
>          .....
>
> class Subgroup(models.Model):
>         subGroupName = models.CharField(maxlength=255,primary_key=True)
>         .....
>
>
> >
>

--~--~---------~--~----~------------~-------~--~----~
 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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to