django-1.5

Python Tuple to Dict, with additional list of keys

风流意气都作罢 提交于 2020-07-05 06:57:37
问题 So I have this array of tuples: [(u'030944', u'20091123', 10, 30, 0), (u'030944', u'20100226', 10, 15, 0)] And I have this list of field names: ['id', 'date', 'hour', 'minute', 'interval'] I would like to, in one fell swoop if possible, to convert the list of tuples to a dict: [{ 'id': u'030944', 'date': u'20091123', 'hour': 10, 'min': 30, 'interval': 0, },{ 'id': u'030944', 'date': u'20100226', 'hour': 10, 'min': 15, 'interval': 0, }] 回答1: data = [(u'030944', u'20091123', 10, 30, 0), (u

Python Tuple to Dict, with additional list of keys

橙三吉。 提交于 2020-07-05 06:57:16
问题 So I have this array of tuples: [(u'030944', u'20091123', 10, 30, 0), (u'030944', u'20100226', 10, 15, 0)] And I have this list of field names: ['id', 'date', 'hour', 'minute', 'interval'] I would like to, in one fell swoop if possible, to convert the list of tuples to a dict: [{ 'id': u'030944', 'date': u'20091123', 'hour': 10, 'min': 30, 'interval': 0, },{ 'id': u'030944', 'date': u'20100226', 'hour': 10, 'min': 15, 'interval': 0, }] 回答1: data = [(u'030944', u'20091123', 10, 30, 0), (u

Django Model is saved, but returns None

 ̄綄美尐妖づ 提交于 2020-01-22 20:50:17
问题 I have a simple model with a Model Manager: class CompanyReviewManager(models.Manager): def get_votes_for_company(self, company): try: return CompanyReview.objects.filter(user = user).count() except ObjectDoesNotExist: return None def get_rating_for_field(self, installer, field): try: return CompanyReview.objects.filter(user = user).aggregate(Avg(field)) except ObjectDoesNotExist: return None class CompanyReview(models.Model): user = models.ForeignKey(settings.AUTH_USER_MODEL) satisfaction =

Django Model is saved, but returns None

こ雲淡風輕ζ 提交于 2020-01-22 20:50:07
问题 I have a simple model with a Model Manager: class CompanyReviewManager(models.Manager): def get_votes_for_company(self, company): try: return CompanyReview.objects.filter(user = user).count() except ObjectDoesNotExist: return None def get_rating_for_field(self, installer, field): try: return CompanyReview.objects.filter(user = user).aggregate(Avg(field)) except ObjectDoesNotExist: return None class CompanyReview(models.Model): user = models.ForeignKey(settings.AUTH_USER_MODEL) satisfaction =

Can't access users in admin after migration

给你一囗甜甜゛ 提交于 2020-01-05 18:42:23
问题 So I successfully migrated from a profile model to an extended User model. The data migration all worked fine, but I can't access my users from the admin, I get the following error: DatabaseError: (1146, "Table 'mydb.app_myuser_groups' doesn't exist") All I have defined in models.py is the following: class MyUser(AbstractUser): isSpecial = models.BooleanField(default=True) having followed these instructions. Is there more I need to do to get this to work? 回答1: See my previous answer here and

Can't access users in admin after migration

杀马特。学长 韩版系。学妹 提交于 2020-01-05 18:39:43
问题 So I successfully migrated from a profile model to an extended User model. The data migration all worked fine, but I can't access my users from the admin, I get the following error: DatabaseError: (1146, "Table 'mydb.app_myuser_groups' doesn't exist") All I have defined in models.py is the following: class MyUser(AbstractUser): isSpecial = models.BooleanField(default=True) having followed these instructions. Is there more I need to do to get this to work? 回答1: See my previous answer here and

Django admin does not login properly with custom User model

↘锁芯ラ 提交于 2020-01-02 02:11:11
问题 I upgraded an app I had on Django 1.4.5 to Django 1.5 and just finished migrating over to a custom User model. When I login to my app, using my own authentication form, with my superuser credentials (created when doing manage.py syncdb ) everything works fine. I am able to get authenticated and if I go to /admin , I am already logged in, as expected. I am able to navigate and use the Admin panel perfectly. However, if I try to login to the admin panel from /admin , using the django admin

How to customize a Django ModelForm

不打扰是莪最后的温柔 提交于 2019-12-25 02:53:45
问题 I want to build a form based on my customer model. In the form, the logged-in user specifies the payee, types in an amount and selects the account he wants to pay from. This is the model and the form thus far: class Payment(models.Model): payee = models.ForeignKey(Customer) amount = models.IntegerField() accounts = models.ManyToManyField(BankAccount) class PaymentForm(forms.ModelForm): class Meta: model = Customer widgets = { 'accounts': forms.CheckboxSelectMultiple(), } The problem with this

FieldError: Local field 'password' in class 'User' clashes with field of similar name from base class 'AbstractBaseUser'?

五迷三道 提交于 2019-12-24 14:36:08
问题 I am using Django 1.5. I have the following model: class User(AbstractBaseUser): #id = models.IntegerField(primary_key=True) #identifier = models.CharField(max_length=40, unique=True, db_index=True) username = models.CharField(max_length=90, unique=True, db_index=True) create_time = models.DateTimeField(null=True, blank=True) update_time = models.DateTimeField(null=True, blank=True) email = models.CharField(max_length=225) password = models.CharField(max_length=120) external = models

Authenticating a custom user in Django 1.5

心不动则不痛 提交于 2019-12-24 03:25:54
问题 I have a custom user in a Django 1.5 project, which uses the email field as the username: class MyUser(AbstractUser): my_custom_field = models.CharField(max_length=20, blank=True, null=True) USERNAME_FIELD = 'email' MyUser._meta.get_field_by_name('email')[0]._unique = True MyUser.REQUIRED_FIELDS.remove('email') If I try to authenticate that user like so: auth_user = authenticate(username=email, password=password) login(request, auth_user) I get this: Traceback: File "/Users/user/dev/proj/app