django-1.8

Django + PostgreSQL: Fill missing dates in a range

℡╲_俬逩灬. 提交于 2021-01-27 05:31:42
问题 I have a table with one of the columns as date . It can have multiple entries for each date. date ..... ----------- ----- 2015-07-20 .. 2015-07-20 .. 2015-07-23 .. 2015-07-24 .. I would like to get data in the following form using Django ORM with PostgreSQL as database backend: date count(date) ----------- ----------- 2015-07-20 2 2015-07-21 0 (missing after aggregation) 2015-07-22 0 (missing after aggregation) 2015-07-23 1 2015-07-24 1 Corresponding PostgreSQL Query: WITH RECURSIVE date_view

Django + PostgreSQL: Fill missing dates in a range

老子叫甜甜 提交于 2021-01-27 05:30:56
问题 I have a table with one of the columns as date . It can have multiple entries for each date. date ..... ----------- ----- 2015-07-20 .. 2015-07-20 .. 2015-07-23 .. 2015-07-24 .. I would like to get data in the following form using Django ORM with PostgreSQL as database backend: date count(date) ----------- ----------- 2015-07-20 2 2015-07-21 0 (missing after aggregation) 2015-07-22 0 (missing after aggregation) 2015-07-23 1 2015-07-24 1 Corresponding PostgreSQL Query: WITH RECURSIVE date_view

How to get distance field in REST response?

你。 提交于 2020-05-16 13:57:33
问题 I am using GeoDjango GIS for proximity search result based on latitude and longitude. The model, is quiet simple: class Address(gismodels.Model): # partner = models.ForeignKey(Partner, related_name="partner_addresses", on_delete=models.CASCADE) street = gismodels.CharField(max_length=255) city = gismodels.CharField(max_length=255) postcode = gismodels.CharField(max_length=255, null=True, blank=True, default='0000') country = gismodels.CharField(max_length=255) businesses = gismodels

Django runserver from Python script

走远了吗. 提交于 2020-01-19 17:04:06
问题 The normal way to start the Django server is to run the following command from a terminal or a bash script: python manage.py runserver [Ip.addr]:[port] e.g. python manage.py runserver 0.0.0.0:8000 How can I start a Django server from a Python script? One option is the following import os if __name__ == "__main__": os.environ.setdefault("DJANGO_SETTINGS_MODULE", "server.settings") from django.core.management import execute_from_command_line args = ['name', 'runserver', '0.0.0.0:8000'] execute

Adding a FileField to a custom SignupForm with django-allauth

被刻印的时光 ゝ 提交于 2020-01-06 19:55:27
问题 I have the following custom SignupForm (simplified, works perfectly without my_file): class SignupForm(forms.Form): home_phone = forms.CharField(validators=[phone_regex], max_length=15) my_file = forms.FileField() def signup(self, request, user): new_user = ReqInfo( user=user, home_phone=self.cleaned_data['home_phone'], my_file=my_file, ) new_user.save() In models.py: class ReqInfo(models.Model): user = models.OneToOneField(User, on_delete=models.CASCADE, blank=True, null=True) home_phone =

Django get class from string

心已入冬 提交于 2020-01-06 11:34:13
问题 I'm looking for a generic way in Python to instantiate class by its name in similar way how it is done in Java without having to explicitly specify the class name in IF..ELIF condition. This is because I have several different models and serializers and want to make them addressable by parameters in the HTTP request. It is to enhance loose coupling and modularity. For example https://www.domain.com/myapp/sampledata.json?model=<modelname> should get the classes <modelname> and <modelname

Django filter query - doesn't work

不羁的心 提交于 2020-01-05 08:43:26
问题 I have problems with my Django, I want to write a very simple query but it doesn't work. Model: class Games(models.Model): name = models.CharField(max_length=128) path_to_folder = models.CharField(max_length=256) description = models.TextField() cover = models.URLField() def __str__(self): return self.name I am trying something like this (It should find itself in my opinion): >>> from gamepanel.models import Games >>> e = Games.objects.all() >>> print (e) [<Games: Call Of Duty 4>] >>> e[0]

Using azure as a storage backend for Django (using django-storages)

瘦欲@ 提交于 2020-01-05 01:43:09
问题 I am using django-storages which I have used in the past to work with AWS S3. But with Microsoft Azure I am running into errors which return no results on google. I am developing using python 3 and Django 1.8.4. I am using django-storages and django-storages-redux for python 3 support. When calling ./manage.py collectstatic and enter yes I get two (!) errors: Traceback (most recent call last): File "/Users/mac/.virtualenvs/bratwurst/lib/python3.4/site-packages/storages/backends/azure_storage

Selenium WebDriverException: Reached error page

主宰稳场 提交于 2020-01-01 04:46:08
问题 I am following a Django TDD tutorial at: http://www.marinamele.com/taskbuster-django-tutorial/taskbuster-working-environment-and-start-django-project I get the following error when running 'all_users.py' before and after I start the development server 'python manage.py runserver' : Traceback (most recent call last): File "functional_tests/all_users.py", line 15, in test_it_worked self.browser.get('http://localhost:8000') File "/Users/samgao/.virtualenvs/tb_test/lib/python3.6/site->packages

auth_user error with Django 1.8 and syncdb / migrate

两盒软妹~` 提交于 2019-12-31 08:55:09
问题 When upgrading to Django 1.8 (with zc.buildout) and running syncdb or migrate, I get this message: django.db.utils.ProgrammingError: relation "auth_user" does not exist One of my models contains django.contrib.auth.models.User: user = models.ForeignKey( User, related_name='%(app_label)s_%(class)s_user', blank=True, null=True, editable=False ) Downgrading to Django 1.7 removes the error. Do I have to include the User object differently in Django 1.8? 回答1: I fix this by running auth first, then