django-1.7

Runtime error:App registry isn't ready yet

若如初见. 提交于 2019-12-03 19:06:52
问题 I am trying to create a script that populates a database with test users. I am new to Django and Python. I keep on getting: Runtime error: App registry isn't ready yet. Here is the output and error: starting population script Traceback (most recent call last): File "populate.py", line 32, in <module> populate() File "populate.py", line 22, in populate i.save() File "c:\Python27\lib\site-packages\django-1.7a2-py2.7.egg\django\db\models\base.py", line 603, in save force_update=force_update,

Django - custom admin page not related to a model

一笑奈何 提交于 2019-12-03 17:37:44
I am using Django 1.7 with Mezzanine. I would like to have some page in admin, where the staff can call some actions (management commands etc.) with buttons and other control elements. I would also like to avoid creating new model, or manually create a template and add link to it (if possible). What is the most common/clean ways how to achieve that? Actually it is simpler. Just before urlpatterns in urls.py patch admin urls like that: def get_admin_urls(urls): def get_urls(): my_urls = patterns('', url(r'^$', YourCustomView,name='home'), ) return my_urls + urls return get_urls admin

Django: passing JSON from view to template

雨燕双飞 提交于 2019-12-03 17:35:30
问题 In views.py , I have time series data stored in a dictionary as follows: time_series = {"timestamp1": occurrences, "timestamp2": occurrences} where each timestamp is in unix time and occurrences is an integer. Is there a way to pass the time series data as a json object in the context of the render function? Why do this: I am using Cal-heatmap on the front end which requires the data to be in json format. Ajax requests work just fine for now but I ideally would like to use the render approach

Models.DateField Format issues

半腔热情 提交于 2019-12-03 16:29:53
I have a model, which has a date field date_of_birth = models.DateField(blank=True, null=True, verbose_name="DOB") I would like to format it to save dates in the format dd/MM/yyyy , but everything I have tried fails. I think the default must be YYYY-MM-dd because that is how it saves to my database. Trying to submit dates in a different format gives the error: [u"'17/01/1970' value has an invalid date format. It must be in YYYY-MM-DD format."] I have tried using Date Widgets but am having a few issues getting it to be compatible with my models.py You can change this by overriding input_formats

ProgrammingError: relation “django_session” does not exist error after installing Psycopg2

ぐ巨炮叔叔 提交于 2019-12-03 14:29:39
问题 I started to develop a Django base web application. Everything were fine until I installed Psycopg2 for my database which I created in PstgreSql . Now when I'm trying to open any page in my site, it throws ProgrammingError: relation "django_session" does not exist error. Request Method: GET Request URL: http://127.0.0.1:8000/login/ Django Version: 1.7 Exception Type: ProgrammingError Exception Value: relation "django_session" does not exist LINE 1: ...ession_data", "django_session"."expire

Django creating a custom model field

不问归期 提交于 2019-12-03 07:56:37
问题 I am trying to create a custom field in Django which will take a decimal currency value (example: £1.56) and save it in the database as an Integer (example: 156) to store currency values. This is what I have so far (I have put fixed values to test) class CurrencyField(models.DecimalField): __metaclass__ = models.SubfieldBase def get_internal_type(self): return 'PositiveIntegerField' def to_python(self, value): print "CurrentField to_python" return Decimal(value)/100 def get_db_prep_value(self

Add non-null and unique field with already populated model

邮差的信 提交于 2019-12-03 04:47:56
I have one model in my app running in a server with a few entries. I need to add a SlugField , unique and not-null for this model. The SlugField will be populated based on trading_name . I've changed my model in order to add this new field and modified save method: class Supplier(StatusModel): SLUG_MAX_LENGTH = 210 slug = models.SlugField(unique=True, max_length=SLUG_MAX_LENGTH) trading_name = models.CharField(max_length=200, verbose_name=_('trading name')) ... def save(self, *args, **kwargs): self.slug = orig = slugify(self.trading_name)[:Supplier.SLUG_MAX_LENGTH] for x in itertools.count(1):

AttributeError while using Django Rest Framework with serializers

▼魔方 西西 提交于 2019-12-03 01:08:30
I am following a tutorial located here that uses Django Rest Framework , and I keep getting a weird error about a field. I have the following model in my models.py from django.db import models class Task(models.Model): completed = models.BooleanField(default=False) title = models.CharField(max_length=100) description = models.TextField() Then my serializer in serializers.py from rest_framework import serializers from task.models import Task class TaskSerializer(serializers.ModelSerializer): class Meta: model = Task fields = ('title', 'description', 'completed') and my views.py as follows: from

Django 1.7 migration error

*爱你&永不变心* 提交于 2019-12-02 20:17:38
问题 I changed a field from CharField to ForeignKey on a Model called Availability, when I am trying to migrate I keep getting the error below: ValueError: Lookup failed for model referenced by field reservation.Availability.location: useraccount.Location Any idea why this could be happening? Thanks --------------UPDATED CODE-------------- App: reservation from useraccount.models import Location class Availability(models.Model): location = models.ForeignKey(Location) App: useraccount class

Django 1.7 migration error

為{幸葍}努か 提交于 2019-12-02 08:51:22
I changed a field from CharField to ForeignKey on a Model called Availability, when I am trying to migrate I keep getting the error below: ValueError: Lookup failed for model referenced by field reservation.Availability.location: useraccount.Location Any idea why this could be happening? Thanks --------------UPDATED CODE-------------- App: reservation from useraccount.models import Location class Availability(models.Model): location = models.ForeignKey(Location) App: useraccount class Location(models.Model): town = models.CharField(max_length=100) county = models.CharField(max_length=100) def