On Thursday, June 7, 2012 11:22:56 PM UTC-6, rahajiyev wrote:
>
>
> > MyModel.objects.extra(select={'rowid': "rowid || ''"}) 
> > 
> Thanks. I don't think extra() takes primary_key=True, does it? 
> I wouldn't want Django to auto-add column id otherwise. 
>
> Assuming I have: 
> MyModel.objects.extra(select={'id': "rowid || ''"}) 
> OK, that's fine for fetching the ID itself, suitable for creating 
> forms. But what if I want to fetch an item by this virtual PK, or 
> update by PK with or without prior fetching?


I haven't tried it, but for those you should be able to use an extra where, 
similar to the extra select above.

MyModel.objects.extra(where=["rowid = 
whatever_syntax_you_need"]).update(cake="lie")

If using .extra() on all your queries isn't acceptable, you should be able 
to write a custom Field class for rowids and add that to your models with 
primary_key=True.  It will probably break syncdb (but I assume this is a 
pre-existing table anyway if you need to use rowids).

https://docs.djangoproject.com/en/dev/howto/custom-model-fields/

Cheers,
Ian

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/0EGkINIYbYUJ.
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