That's because of my example. I have a LEGO Set model:
class Set(models.Model):
lego_id = models.CharField(max_length=
32, primary_key=True, blank=True) #lego_id stores the unique number that's
on every Lego box
text_name = models.CharField(max_length=64)
#...
And I resolved my problem by adding primary_key=True, like you said. (I
hope it's OK if the pk is a CharField?). Now the link works fine, and the
lego_id is the link, like so:
(r'^sets/(?P<pk>\d+)/$', SetDetailView.as_view(
model=Set,
context_object_name="set_details",
template_name='data/set_details.html',
)),
But the site is empty. Here's my extremely simple template:
{% block title %}{{ set.text_name }}{% endblock %}
{% block content %}
<h2>Set:</h2>
{{ set.theme }} - {{ set.subtheme }}
{% endblock %}
All I can see is the one " - " :).
EDIT: made a typo in the last post.
W dniu niedziela, 8 lipca 2012 15:53:02 UTC+2 użytkownik Tomas Neme napisał:
>
> > Turns out that's the problem. I wanted to use a field from my Car model:
> > car_id, so the link on the website would look like:
> > www.blablabla.com/cars/3421, where 3421 is the car_id. Unfortunately,
> the
> > car_id is not the same as <pk>. Can I achieve something like that with
> class
>
> what's car_id and why isn't it your PK?
>
> you should post your full models when asking for help, in general.
>
> As a general rule, having a car_id field in a Car model is
> unnecessary. Models come with ids of their own by default, you don't
> need to define them. If you have IDs of your own that you want to
> reflect in your database, first of all, I'd call it just "id", so you
> can do my_car.id, my_car.car_id sounds a little bit redundant to my
> taste, and secondly, you can define it as id =
> models.IntegerField(primary_key=True). If you do that, your pk will be
> the ID you defined (you can do this with a CharField as well, I think)
>
> --
> "The whole of Japan is pure invention. There is no such country, there
> are no such people" --Oscar Wilde
>
> |_|0|_|
> |_|_|0|
> |0|0|0|
>
> (\__/)
> (='.'=)This is Bunny. Copy and paste bunny
> (")_(") to help him gain world domination.
>
--
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/-/9DJ8GkkxvCMJ.
To post to this group, send email to [email protected].
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.