These are chat archives for django/django

31st
Jul 2017
shiwoopark
@Shiwoo-Park
Jul 31 2017 01:47
Is there anyone who knows about library or open source that make django project organized (function or class) comments into documentation?
Ghost
@ghost~58e3220cd73408ce4f55e9fb
Jul 31 2017 07:06
Hello
Can someone analyse this Jinja2 template snippet for me? I have no idea why it is wrong, and am looking it up. The code was from a previous developer.
<input type="text" class="form-control" id="l_fullname" name="fullname" {%="" if="" fullname="" %}="" value="{{fullname}}" endif="">
Chris Cheng
@cheng337002
Jul 31 2017 08:04
hi everyone, i use the django-rest-framework, when i post to create data, i got the django.db.utils.IntegrityError: duplicate key value violates unique constraint, the model pk is autofield, it can't auto create with last id?
shiwoopark
@Shiwoo-Park
Jul 31 2017 08:26
Can i see the table DDL?
And Django Model
@cheng337002
Lim H.
@limdauto
Jul 31 2017 10:28
@Shiwoo-Park hey this is not really django -specific but are you looking for something similar to sphinx autodoc? http://www.sphinx-doc.org/en/stable/ext/autodoc.html
DanielAlderman
@DanielAlderman
Jul 31 2017 15:34
Hi, does anyone know if it's possible to annotate a database object returned by .get() in the same manner you can annotate a queryset returned by .filter()?
Lim H.
@limdauto
Jul 31 2017 15:53
it works the same way right?
In [10]: u = User.objects.annotate(next_id=models.F('id')+1).get(username='foo')

In [11]: u.id
Out[11]: 2224242

In [12]: u.next_id
Out[12]: 2224243
DanielAlderman
@DanielAlderman
Jul 31 2017 15:58
You're quite right, I was trying to add the .annotate() AFTER the .get()
Which doesn't work ^_^
DanielAlderman
@DanielAlderman
Jul 31 2017 16:28
@limdauto: Do you know if it's possible to annotate a new object? So say I do user u = User(name='test') canI just put the .annotate() on the end?
Lim H.
@limdauto
Jul 31 2017 16:29
:D annotate is just an orm abstraction of setattr
so if you want just do u.whatever_property = 'foo'
what exactly are you trying to accomplish?
DanielAlderman
@DanielAlderman
Jul 31 2017 16:36
Bit difficult to explain!
Basically I'm trying to annotate several numeric fields onto my primary table
these numbers are summed from the values of another table
But the info is being fed in from an external database hence why i'm making new objects.
I've got it working if i'm updating an existing row
but not new rows
Lim H.
@limdauto
Jul 31 2017 16:39
okay I see what you mean. IMHO you should separate read/write in your data flow. Annotate happens on read. You can calculate aggregation manually by reading and then set the aggregated results on your object then write.