Z
Z
zigen2015-07-24 14:36:20
Django
zigen, 2015-07-24 14:36:20

How to use Username as slug?

Good afternoon.
Tell me how to use the username field of the model as a slug when working with CBV (for example, generic.DetailVew)
I suppose that you can override the slig_field attribute in the SingleObjectmixin mixin?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander, 2015-07-26
@zigen

zigen : Understood

And misunderstood.
slug_field [ get_slug_field() ]
class MyClassDetailView(DetailView):
    model = User
    slug_field = 'username'

For def get_object() is used for "little" other purposes. For example, for NOT explicit filtering (figuratively speaking "only for male users", "only objects with the status - display" and so on). You pass "slug" in the address bar, this is an explicit parameter and for this there is a banal and correct slug_field .

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question