These are chat archives for django/django

23rd
Nov 2016
Andrew Backer
@awbacker
Nov 23 2016 08:54
At least I see it with postgres jsonb fields
Seems to be a change in postgres 9.4.1 (https://www.postgresql.org/docs/9.4/static/release-9-4-1.html). - Fix jsonb Unicode escape processing, and in consequence disallow \u0000 (Tom Lane)
jsondata = {'bad': u'\u0000', 'other': 'good'} ;   # \u0000 = \x00
obj.save()
DataError: unsupported Unicode escape sequence
LINE 1: ...d" = 95, "flags" = ARRAY['f1'], "jsondata" = '{"bad": "...
DETAIL:  \u0000 cannot be converted to text.
CONTEXT:  JSON data, line 1: {"bad":...
Andrew Backer
@awbacker
Nov 23 2016 09:02
I suppose you could just string.replace(bad, u'\u0000', 'wasnull')
rjvcoder
@rjvcoder
Nov 23 2016 17:14
Hi! Anyone having problem after upgrading from Django 1.9 to 1.10? I cant seem to connect to local. It says 127.0.0.1 didn’t send any data.
ERR_EMPTY_RESPONSE
rjvcoder
@rjvcoder
Nov 23 2016 18:27
Oops..nvm just scanned for some spamware, and now it works. ;)
Sherif O.
@shadowsyntax
Nov 23 2016 19:09

I have a form generated from the model below

class RefGen(models.Model):
    letter_date = models.DateField(default=timezone.now)
    dispatch_date = models.DateField(null=True, blank=False)
    to_whom = models.CharField(max_length=50)
    letter_subject = models.CharField(max_length=100)
    org_units = models.CharField(max_length=50, choices=DEPARTMENTAL_NAMES)
    ref_number = models.IntegerField(default=0000)

ref_number is hidden but i want to increment it’s value by 1 from it’s previous value pulled form the db and save with the current form. That is if RefGen.objects.all().last(‘ref_number’) is 0 then when i save the current form the ref_number should be saved as 1 in the db. How do i go about this?

Sherif O.
@shadowsyntax
Nov 23 2016 20:10
how do i create a table in django admin with my model such that each field in my model will be a column header
kpagcha
@kpagcha
Nov 23 2016 20:10
a question about django templates and the include tag: I reduced a really long file into different partials, some of which are included hundred of times (like items in a list, and the item view is a partial). However, I was told this would impact A LOT in the performance of the site. So... how bad is this situation? and how am I supposed to use the template system in an smart way without damaging the performance too much?
J. Dalton Childers
@jdaltonchilders
Nov 23 2016 22:58

Does anyone know how to query a separate table with the primary key of another table? Originally, we had a foreign key setup from the tweets table to the study table, but due to some issues with foreign key reassignment in our table partition scheme we had to abandon this approach. From a study’s detail view page (we’re using class based views) I’d like to show a list of the tweets from a given study, the total amount of tweets (so I’ll be using count), etc.

Study/Models.py

class Study(models.Model):
    name = models.CharField(max_length=128, unique=True)
    start_date = models.DateField()
    end_date = models.DateField()
    owner = models.ForeignKey(User, default=1, related_name="owner")
    quota = models.IntegerField(default=0)

Study/Models.py

class Tweet(models.Model):
    study = models.IntegerField()
    data = JSONField()

Study/Views.py

class StudyDetailView(PermissionRequiredMixin, DetailView):
    model = Study
    permission_required = ['view_study']
    return_403 = True

Study/Urls.py

url(r'^detail/(?P<pk>\d+)/$', views.StudyDetailView.as_view(), name="study_detail”),