Re: URLs: mymodel_id vs object_id vs pk ....

2014-06-05 Thread Thomas Güttler

Thank you for answering my question.

Unfortunately "slug" does not work in my context.

My model does not have a "slug". It is like a ticket/issue system. There
are several hundred of tickets each day.

  Thomas Güttler

Am 04.06.2014 15:07, schrieb Thomas Güttler:

What is the best practice for named URL parameter which refer to a primary key 
of a model?

I have seen many ways:

  - object_id
  - mymodel_id
  - pk
  - id
  - .

example:

urlpatterns = [
 url(r'^article/(?P\d+)/$', 'article.view'),
 ...
 ]

Up to now we used "mymodel_id" but it gets boring to type in "mymodel".

This is a question about best practice:

Which do you use (and why)?


Related: https://docs.djangoproject.com/en/dev/topics/http/urls/#named-groups

   Thomas



--
You received this message because you are subscribed to the Google Groups "Django 
users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/53903B4C.7070409%40tbz-pariv.de.
For more options, visit https://groups.google.com/d/optout.


Re: URLs: mymodel_id vs object_id vs pk ....

2014-06-04 Thread Sergiy Khohlov
Jnt of the best way is a slug.
 I nether do use id or object_id by security reason (hacker can try to
access another object or  count on objects in your application, such as
administrator usually  has id as 0 or small number. It is good target for
attack). Keep in mind that id is mutable after moving to the new database
(ex: you can not use direct link to the product in your webshop).

Many thanks,

Serge


+380 636150445
skype: skhohlov


On Wed, Jun 4, 2014 at 4:49 PM, monoBOT  wrote:

> Thats a matter of taste ... i use model_id
>
>
> 2014-06-04 14:07 GMT+01:00 Thomas Güttler :
>
> What is the best practice for named URL parameter which refer to a primary
>> key of a model?
>>
>> I have seen many ways:
>>
>>  - object_id
>>  - mymodel_id
>>  - pk
>>  - id
>>  - .
>>
>> example:
>>
>> urlpatterns = [
>> url(r'^article/(?P\d+)/$', 'article.view'),
>> ...
>> ]
>>
>> Up to now we used "mymodel_id" but it gets boring to type in "mymodel".
>>
>> This is a question about best practice:
>>
>> Which do you use (and why)?
>>
>>
>> Related: https://docs.djangoproject.com/en/dev/topics/http/urls/#
>> named-groups
>>
>>   Thomas
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Django users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to django-users+unsubscr...@googlegroups.com.
>> To post to this group, send email to django-users@googlegroups.com.
>> Visit this group at http://groups.google.com/group/django-users.
>> To view this discussion on the web visit https://groups.google.com/d/
>> msgid/django-users/538F19FF.1090209%40tbz-pariv.de.
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>
>
> --
> *monoBOT*
> Visite mi sitio(Visit my site): monobotblog.alvarezalonso.es
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/CA%2BxOsGD3ePtXWNd-D9AmZ_4mr_%3D3cS_uTi61i5Aou6n7SmZ9QA%40mail.gmail.com
> 
> .
>
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CADTRxJM00kN%3D9sDez34shxpBbweC8CSofbryy%2Bc_cCtQAS8KLg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: URLs: mymodel_id vs object_id vs pk ....

2014-06-04 Thread monoBOT
Thats a matter of taste ... i use model_id


2014-06-04 14:07 GMT+01:00 Thomas Güttler :

> What is the best practice for named URL parameter which refer to a primary
> key of a model?
>
> I have seen many ways:
>
>  - object_id
>  - mymodel_id
>  - pk
>  - id
>  - .
>
> example:
>
> urlpatterns = [
> url(r'^article/(?P\d+)/$', 'article.view'),
> ...
> ]
>
> Up to now we used "mymodel_id" but it gets boring to type in "mymodel".
>
> This is a question about best practice:
>
> Which do you use (and why)?
>
>
> Related: https://docs.djangoproject.com/en/dev/topics/http/urls/#
> named-groups
>
>   Thomas
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-users.
> To view this discussion on the web visit https://groups.google.com/d/
> msgid/django-users/538F19FF.1090209%40tbz-pariv.de.
> For more options, visit https://groups.google.com/d/optout.
>



-- 
*monoBOT*
Visite mi sitio(Visit my site): monobotblog.alvarezalonso.es

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CA%2BxOsGD3ePtXWNd-D9AmZ_4mr_%3D3cS_uTi61i5Aou6n7SmZ9QA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


RE: URLs: mymodel_id vs object_id vs pk ....

2014-06-04 Thread Ilya Kazakevich
If you use "DetailView"
(https://docs.djangoproject.com/en/dev/ref/class-based-views/generic-display
/#django.views.generic.detail.DetailView) you may call this field "slug" (it
is default). But you can overwrite it.

But in your case custom function is used, so you may call this field
whatever you want. 
I believe "id" is nice.

I use DetailView unless I need really custom logic, so I use "slug" almost
always.

Ilya Kazakevich,
JetBrains PyCharm (Best Python/Django IDE)
http://www.jetbrains.com/pycharm/
"Develop with pleasure!"


>-Original Message-
>From: django-users@googlegroups.com
>[mailto:django-users@googlegroups.com] On Behalf Of Thomas Guttler
>Sent: Wednesday, June 04, 2014 5:07 PM
>To: django-users@googlegroups.com
>Subject: URLs: mymodel_id vs object_id vs pk 
>
>What is the best practice for named URL parameter which refer to a primary
key
>of a model?
>
>I have seen many ways:
>
>  - object_id
>  - mymodel_id
>  - pk
>  - id
>  - .
>
>example:
>
>urlpatterns = [
> url(r'^article/(?P\d+)/$', 'article.view'),
> ...
> ]
>
>Up to now we used "mymodel_id" but it gets boring to type in "mymodel".
>
>This is a question about best practice:
>
>Which do you use (and why)?
>
>
>Related:
>https://docs.djangoproject.com/en/dev/topics/http/urls/#named-groups
>
>   Thomas
>
>--
>You received this message because you are subscribed to the Google Groups
>"Django users" group.
>To unsubscribe from this group and stop receiving emails from it, send an
email to
>django-users+unsubscr...@googlegroups.com.
>To post to this group, send email to django-users@googlegroups.com.
>Visit this group at http://groups.google.com/group/django-users.
>To view this discussion on the web visit
>https://groups.google.com/d/msgid/django-users/538F19FF.1090209%40tbz-pari
>v.de.
>For more options, visit https://groups.google.com/d/optout.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/03fe01cf7ff8%24c969ba00%245c3d2e00%24%40JetBrains.com.
For more options, visit https://groups.google.com/d/optout.


Re: URLs: mymodel_id vs object_id vs pk ....

2014-06-04 Thread Juergen Schackmann
I am not aware of any best practices for wording here, though my general 
recommendaton would the wording should be identical to the attribute name 
of the model, e.d. 'id', 'slug' or whatever. I would not add the "mymodel" 
prefix as long as it becomes clear from the context to which model it 
belongs to. 

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/27c1ef21-12a1-4ad7-8552-ce9747e9b819%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.