django-1.7

What's the difference between authenticate and login?

↘锁芯ラ 提交于 2019-12-30 06:07:13
问题 Documentation: https://docs.djangoproject.com/en/1.7/topics/auth/default/#django.contrib.auth.login When you’re manually logging a user in, you must call authenticate() before you call login(). authenticate() sets an attribute on the User noting which authentication backend successfully authenticated that user (see the backends documentation for details), and this information is needed later during the login process. An error will be raised if you try to login a user object retrieved from the

What's the difference between authenticate and login?

本小妞迷上赌 提交于 2019-12-30 06:07:06
问题 Documentation: https://docs.djangoproject.com/en/1.7/topics/auth/default/#django.contrib.auth.login When you’re manually logging a user in, you must call authenticate() before you call login(). authenticate() sets an attribute on the User noting which authentication backend successfully authenticated that user (see the backends documentation for details), and this information is needed later during the login process. An error will be raised if you try to login a user object retrieved from the

How to JSON serialize __dict__ of a Django model?

≡放荡痞女 提交于 2019-12-30 04:30:19
问题 I want to serialize the values of a single model in Django. Because I want to use get() , values() is not available. However, I read on Google Groups that you can access the values with __dict__ . from django.http import HttpResponse, Http404 import json from customer.models import Customer def single(request, id): try: model = Customer.objects.get(id=id, user=1) except Customer.DoesNotExist: raise Http404 values = model.__dict__ print(values) string = json.dumps(values) return HttpResponse

Django 1.7 migrations: django.db.utils.OperationalError: no such table: db_trans_language

三世轮回 提交于 2019-12-25 03:32:25
问题 I'm working on a django project and have had some migration troubles in my (test)prod setting and as a consequence have I dumped all relevant data and I am now in the process of setting up the database from scratch. Here is what happens: I remove all (potentially) faulty migrations from the app I run makemigrations I run migrate I am presented with the following error: Error: C:\Users\Sverker\Dropbox\Picrates>python manage.py makemigrations db_trans C:\Users\Sverker\Dropbox\Picrates\picrates

Filter Models based on content type django 1.7

好久不见. 提交于 2019-12-24 13:27:34
问题 My models.py looks like class OneTimeEvent(models.Model): title = models.CharField(max_length = 160) location = models.CharField(max_length = 200, blank = True) event_date = models.DateTimeField('event date',blank = True, null = True) price = models.IntegerField(max_length = 20, blank = True, null = True) seats = models.IntegerField(max_length = 20, blank = True, null = True) abstract = models.TextField() event_plan = models.TextField() available_seats = models.IntegerField(max_length = 20,

What's the Django 1.7+ equivalent to South's add_ignored_fields()?

為{幸葍}努か 提交于 2019-12-23 22:24:59
问题 Back in previous versions of Django, we all used South to do migrations, and because it wasn't as smart as we might have liked, we sometimes needed to tell it to explicitly ignore some fields because such fields were too complicated for it to handle. We did this with add_ignored_fields and everything pretty much worked. In our case, we have a "field" on our model that's a subclass of CharField that actually attaches two additional fields to the model via the contribute_to_class method. It's

Django Model __unicode__ raising exception when logging

血红的双手。 提交于 2019-12-23 12:32:29
问题 I have a model class that looks like the following: class Address(models.Model): # taking length of address/city fields from existing UserProfile model address_1 = models.CharField(max_length=128, blank=False, null=False) address_2 = models.CharField(max_length=128, blank=True, null=True) address_3 = models.CharField(max_length=128, blank=True, null=True) unit = models.CharField(max_length=10, blank=True, null=True) city = models.CharField(max_length=128, blank=False, null=False) state_or

Add a boolean field if a row exists in another table?

巧了我就是萌 提交于 2019-12-22 17:55:16
问题 I have two tables called Post and Reply . The users can create just one Response for each Post . The models look like this: class Post(models.Model): name = models.CharField(max_length = 100) class Reply(models.Model): post = models.ForeignKey(Post, related_name = 'replies') Now, I have a view that returns the posts, like this: class PostList(generics.ListAPIView): permission_classes = (permissions.IsAuthenticated,) queryset = Post.objects.all() serializer_class = PostSerializer And a

Django 1.7 ImageField form validation

前提是你 提交于 2019-12-22 09:32:59
问题 I'm writing unit tests using Django 1.7 with Python 3.4. The form below validates fine when the file_data element is commented out. With the file_data included it doesn't validate and the test fails. from django.core.files.uploadedfile import SimpleUploadedFile ... data = { 'phone_number': '123456', 'job': Job.objects.latest('id').pk, } file_data = { 'portrait': SimpleUploadedFile( content=b'', content_type='image/jpeg', name='test.jpg', ) } form = PersonForm(data, file_data) self.assertTrue

Upgrading transaction.commit_manually() to Django > 1.6

*爱你&永不变心* 提交于 2019-12-22 04:42:36
问题 I have inherited some code for an app that was written for Django 1.4. We need to update the codebase to work with Django 1.7, and eventually 1.8 as the next Long Term Support release. In a few places it uses the old style @transaction.commit_manually and with transaction.commit_manually: I do not know enough about transactions in general but I am trying to understand what they are used for, so I can either remove them (if unnecessary) or upgrade them to the newer set_autocommit(False) or