django-1.7

Avoiding race condition between validation for uniqueness and insertion

你说的曾经没有我的故事 提交于 2021-02-08 05:16:26
问题 I have a Django 1.7 beta 1 project with a standard user signup form. Conceptually, it makes sense for the form validation to fail if the username is already taken. However, the form validation and the saving of the successfully created user model are separate steps, so there's a race condition where the validation can pass but the actual user.save() can fail with an IntegrityError . I'm unclear on what happens if both the form validation and the user.save() step are wrapped in the same

Avoiding race condition between validation for uniqueness and insertion

被刻印的时光 ゝ 提交于 2021-02-08 05:15:21
问题 I have a Django 1.7 beta 1 project with a standard user signup form. Conceptually, it makes sense for the form validation to fail if the username is already taken. However, the form validation and the saving of the successfully created user model are separate steps, so there's a race condition where the validation can pass but the actual user.save() can fail with an IntegrityError . I'm unclear on what happens if both the form validation and the user.save() step are wrapped in the same

Django fixtures save with default value

孤者浪人 提交于 2021-02-07 14:20:47
问题 I'm using Django 1.7 and I have a problem with my fixtures. I would like Django to use the default value or use the save() method to create unspecified values. Here are my current objects: # File: uuidable.py import uuid from django.db import models from django.utils.translation import ugettext_lazy as _ class Uuidable(models.Model): uuid = models.CharField(_('uuid'), blank=True, null=False, unique=True, max_length=64, default=uuid.uuid4()) # Tried here class Meta: abstract = True def save

Django: Generic views based 'as_view()' method

南笙酒味 提交于 2020-08-18 11:00:25
问题 I was working on an application wherein I created a generic ListView . Now, while defining that view in my urls.py , I read from the documentation that I need to use the as_view() method as follows: from django.conf.urls import patterns, include, url from .views import BlogIndex urlpatterns = patterns( '', url(r'^$', BlogIndex.as_view(), name="index"), ) Now, I didn't really understood what the documentation had to say about this method. Can someone shed some light into this concept? 回答1: In

Error Using django-tables2 - Expected table or queryset, not 'str'

纵然是瞬间 提交于 2020-07-17 06:28:21
问题 I am trying to create some tables for my application using django-tables2 and running into some difficulties. I am using Python 2.7, and Django 1.7. I am following the tutorial, and I ran into problems. I reach the point where I need to create a Table class for customization. However, whenever I do so, I get the following error: Expected table or queryset, not 'str'. After doing some research it looks like I am using an older version of django-tables2. However, I just installed it yesterday

django: create user profile for existing users automatically

為{幸葍}努か 提交于 2020-01-22 17:11:07
问题 I added a new UserProfile Model to my project today. class UserProfile(models.Model): user = models.OneToOneField(User) ... def __unicode__(self): return u'Profile of user: %s' % (self.user.username) class Meta: managed = True def create_user_profile(sender, instance, created, **kwargs): if created: profile, created = UserProfile.objects.get_or_create(user=instance) post_save.connect(create_user_profile, sender=User) The above code will create a user profile for each new created user. But how

Django: Exception Value (2013, '2013: Lost connection to MySQL server during query', None)

安稳与你 提交于 2020-01-04 13:31:51
问题 Recently I have upgraded Django from version 1.6.5 to 1.7.1 and mysql-connector-python from 1.x to 2.0.2 After upgrading, the Exception(2013) is raised most of the time I make a query. Exception Type: InterfaceError Exception Value: (2013, '2013: Lost connection to MySQL server during query', None) I have added some settings about 'CONN_MAX_AGE', 'wait_timeout' but it does not help. Here are my settings: From command line: C:/>pip freeze Django==1.7.1 South==1.0.1 mysql-connector-python==2.0

Django: Exception Value (2013, '2013: Lost connection to MySQL server during query', None)

有些话、适合烂在心里 提交于 2020-01-04 13:30:10
问题 Recently I have upgraded Django from version 1.6.5 to 1.7.1 and mysql-connector-python from 1.x to 2.0.2 After upgrading, the Exception(2013) is raised most of the time I make a query. Exception Type: InterfaceError Exception Value: (2013, '2013: Lost connection to MySQL server during query', None) I have added some settings about 'CONN_MAX_AGE', 'wait_timeout' but it does not help. Here are my settings: From command line: C:/>pip freeze Django==1.7.1 South==1.0.1 mysql-connector-python==2.0

Django: Attempt to write a read-only database

自古美人都是妖i 提交于 2020-01-03 18:44:07
问题 I have just created a Django project with python manage.py startapp smartrecruitment I then ran a db sync python manage.py syncdb Operations to perform: Apply all migrations: admin, contenttypes, auth, sessions Running migrations: Applying contenttypes.0001_initial... OK Applying auth.0001_initial... OK Applying admin.0001_initial... OK Applying sessions.0001_initial... OK And added my superuser, but I cannot access /admin in the browser. I have tried doing the following commands to give

django 1.7 migrations — how do I clear all migrations and start over from scratch?

落花浮王杯 提交于 2019-12-31 08:06:05
问题 So I'm rapidly iterating on a django app at the moment and I'm constantly adjusting models.py. Over the course of a day or two of programming and testing I generate a couple dozen migration files. Sometimes I really tear the schema apart and completely re-do it. This causes the migration process to complain a great deal about defaults and null values and so on. If possible, I would just like to scratch all the migration stuff and re-start the migrations now that I finally know what I'm doing.