I have a CharField as my primary_key, and its intent is to act like a UID.
This UID is built from data in other fields on the model instance though.
flenter joined the channel
desmond joined the channel
desmond
Hi, I have a named url that I can access with {% url 'name %}, but how can I access this within python, in a function?
kizzo
A primary key for a VideoFile might be "filename.jpg h3rc1h4" for example, with filename.jpg being the value in some other CharField on the model, and the random characters represent the first 7 or so chars from an MD5 field.
LucSaffre has quit
atula has quit
One of the fields on this model is a ManyToMany to 'self' ; the problem I'm facing is generating a unique UID value when I want to use the add method: video_file.parents.add(new_video)
tbaxter
desmond: look up reverse()
mykul joined the channel
kizzo, I can't help you, but I do think you're making the PK way harder than it has to be. Or should be.
flenter has quit
Ariel_Calzada has quit
kizzo
Maybe I am. I think my goal is to make something like a natural composite key.
hiway has quit
I think maybe I talked about this problem before, and I'm coming to the same conclusions now ha.
tbaxter
Just sounds like a lot of aggravation, and I'm not seeing the advantage
patrick91 joined the channel
livingstn joined the channel
kizzo
My real concern is how beautiful/nice the data looks when in json format - I don't want the primary keys to be integers.
Chunk2 has quit
foxx has quit
tbaxter
what difference does it make, really?
I suppose I'd probably output my json myself if I was feeling super-particular about it.
arphen joined the channel
arphen
Hi!
kizzo
I want to be able to uniquely refer to model instances via an arbitrary selection of model field values, I think.
arphen
My csfrmiddlewaretoken and my csfrtoken cookie have different values. why?
It just looks bad in the fixture, and for later too, when you want to refer to the same model instance, I don't want to have to use an integer.
cleme1mp joined the channel
So I'm like, ok, change the primary_key to a CharField, and then specify a UID-generating algorithm that makes use of theh available info in other fields, to create this field.
bradfordtoney joined the channel
tbaxter
kizzo: I think you should re-read the docs you just linked to. Looks to me like they give you your answer, without jacking with the PK, using use_natural_key
pydonny joined the channel
If I'm reading it right
zzing has quit
kizzo
Yeah ok that's for a different task, but I understand, yeah.
Let me find this other thing..
Chunk2 joined the channel
Dealing with this issue, combined with ManyToManyFields, is the problem I think:
That doc explicitly says that you can't associate until the instance is saved.
bradfordtoney has quit
I have overridden the save method on my Model with just this:
self.compute_uid(*args, **kwargs)
pydonny has quit
super(FileDisk, self).save(*args, **kwargs)
And the job of self.compute_uid() is to set the self.uid attribute/field on the model.
filedisk:filename='file.jpg',md5=blah
klaut joined the channel
mykul_ joined the channel
w66 has quit
mykul has quit
Yeah mabye you're right.
I'll stop trying, and see if I can get away with it.
rgenito has quit
Watabou joined the channel
CheckDavid joined the channel
tbaxter
kizzo: take a look at those docs again. I think you need to leave PK alone and use the natural keys stuff. I've never used it, but it looks like it's made just for what you want to do
Andy80 joined the channel
cotton0x73 joined the channel
kizzo
Yeah. When the database is running, and your site is up, code is running, things are live, the plain integer pk is fine, and the Model.objects.get() method's keyword arguments satisfy the need for looking up things uniquely, enough.
dman777 joined the channel
And when exporting to json, yes the Django parts do that for you.
So I think things are cool.
Andy80 has quit
kradalby has quit
cfoch has quit
cfoch joined the channel
cfoch
I have MyModelDetailView. It shows as a table. The only problem is that ManyToManyFields aren't displayed. I would like to display them as <ul>. How can I do that?
Azelphur has quit
oubiga joined the channel
Ariel_Calzada joined the channel
notsocivilized joined the channel
tbaxter
cfoch: just follow the relation
hoody_k joined the channel
pydonny joined the channel
Tip: look at the admin docs. They'll show all your relations in your models and how to follow them.
Azelphur joined the channel
dman777
I am writing a option to update a database record(that already exists). I will be using a form to populate the preexisting data. I am using class bassed views. Will UpdateView automatically populate the form with the data or do I need to pass that database instance to the form when I do form_class = ModifyForm?
telex has quit
kradalby joined the channel
notsocivilized has quit
telex joined the channel
amigo_ has quit
chrismed has quit
cfoch has quit
amigo has quit
amine has quit
HowardwLo
https://docs.djangoproject.com/en/1.5/ref/contr... I'm following this example for site maps, and I have a working site map for my model. How do you include your homepage in the site map? (or is that not necessary)
eassea joined the channel
tbaxter
HowardwLo: it's not really necessary. If you really want to do it, it's probably easiest to just build a second sitemap file with your index pages
dman777: a simple updateView will do it all for you.
in about three lines
also, don't name your form ModifyForm
Actually, you probably shouldn't have a "modifyForm". You can probably use the same form for creation and updating
rgenito joined the channel
dman777
tbaxter: thanks. Is ModifyForm a reserverd word? Just curious
tbaxter
No, it's just a lousy name. What happens when you write your second app?
dman777
true...good point
cppCzar joined the channel
tbaxter
I don't know what your model is, but generally, you'd want "ModelnameForm" and you could use the same one for both creating and updating
HowardwLo
tbaxter: my index pages don't have models and aren't flat pages (i think). i made a view to serve each template.
zzing joined the channel
tbaxter
right… that's mot unusual. At best, they'd be listviews and the sitemaps framework still wouldn't be very useful. That's why if you really want one, roll your own.
skay has left the channel
Just use a TemplateView and start outputting urls and stuff. It's not that different than building site nav
stwe joined the channel
kizzo has quit
rafaqueque joined the channel
cotton0x73 has quit
cotton0x73 joined the channel
Itkovian joined the channel
bender314 joined the channel
glosoli has quit
livingstn has quit
eddie_lomax joined the channel
bradfordtoney joined the channel
livingstn joined the channel
eassea
I've been having trouble with a NoReverseMatch error for some of my URLs when using the 'url' tag and the 'reverse' function. In trying to debug I've noticed that the reverse_dict being created from my URL patterns appears to have some spurious values that lead to the exception in question being thrown, but I haven't been able to figure out why the erroneous values are there. My URL Conf is https://dpaste.de/Rfhq. Forward resolution
bradfordtoney has quit
the URLs all work properly. The issues with reverse can be seen in this shell transcript (https://dpaste.de/MOgg), as can the contents of the relevant entries in reverse_dict.