django-1.5

Appropriate way to handle deprecated `adminmedia` templatetag and {% admin_media_prefix %}

删除回忆录丶 提交于 2019-12-02 22:12:53
From django 1.5 onwards, https://docs.djangoproject.com/en/1.5/releases/1.5/#miscellaneous The template tags library adminmedia, which only contained the deprecated template tag {% admin_media_prefix %}, was removed. Attempting to load it with {% load adminmedia %} will fail. If your templates still contain that line you must remove it. So what is the appropriate way to replace code found in legacy libraries and my legacy projects which still uses {% load adminmedia %} and loads css like:- <link rel="stylesheet" type="text/css" href="{% load adminmedia %}{% admin_media_prefix %}css/login.css">

AbstractUser Django full example

China☆狼群 提交于 2019-12-02 21:04:56
I am new to Django and I have been trying this for weeks, but could not find a way to solve this problem. I want to store additional information like user mobile number, bank name, bank account. And want to store the mobile number while user registers and wants user to login with either (mobile number and password) or (email and password). This is my UserProfile model from django.db import models from django.contrib.auth.models import User from django.contrib.auth.models import AbstractUser # Create your models here. class UserProfile(AbstractUser): user_mobile = models.IntegerField(max_length

Migrate url tags to django 1.5

风流意气都作罢 提交于 2019-12-02 20:24:53
I'm trying to migrate an old django application to django 1.5, There are 745 urls in different html files as this way: {% url url_name %} If I'm not wrong, this was deprecated and can't be used anymore from django 1.5 (as said here ), and I have to transform all of them into: {% url 'url_name' %} Any idea to do this without going crazy? Maybe, some kind of script, I dont know... I can't imagine a way to do it with replace in path. I'm probably missing something obvious. NOTE: This command is destructive. Use version control or backup your templates directory before running it. You can use sed.

Django 1.5 custom user model - signals limitation

做~自己de王妃 提交于 2019-12-02 19:32:39
问题 It's written in the doc that: Another limitation of custom User models is that you can’t use django.contrib.auth.get_user_model() as the sender or target of a signal handler. Instead, you must register the handler with the resulting User model. See Signals for more information on registering an sending signals. I guess it means you can do the following: from django.contrib.auth import get_user_model User = get_user_model() @receiver(post_save, sender=User) def user_saved(sender=None, instance

When to use the Custom User Model in Django 1.5

ぃ、小莉子 提交于 2019-12-02 18:47:21
I have a question regarding the custom user model in Django 1.5 So right now the default user model looks just fine to me, I just need to add a few other variables such as gender,location and birthday so that users can fill up those variables after they have successfully registered and activated their account. So, what is the best way to implement this scenario? Do I have to create a new app called Profile and inherit AbstractBaseUser? and add my custom variable to models.py? Any good example for me to follow? thank you in advance Dan Hoerst You want to extend your user model to the

Django 1.5 custom user model - signals limitation

末鹿安然 提交于 2019-12-02 09:27:44
It's written in the doc that: Another limitation of custom User models is that you can’t use django.contrib.auth.get_user_model() as the sender or target of a signal handler. Instead, you must register the handler with the resulting User model. See Signals for more information on registering an sending signals. I guess it means you can do the following: from django.contrib.auth import get_user_model User = get_user_model() @receiver(post_save, sender=User) def user_saved(sender=None, instance=None, **kwargs): # something Isn't it? I'm just wondering if I understand well (I don't understand why

Can I change the USERNAME_FIELD in Django 1.5 without creating a custom user?

删除回忆录丶 提交于 2019-11-30 16:55:31
问题 I am trying to use the email field in the default Django user model as the username. I am using Django 1.5 and I saw that the default user has a USERNAME_FIELD property. In my project, I would like to set the following USERNAME_FIELD = 'email' as a default in the user model. This small but fundamental tweak is the only thing I would like to change in the user model. I was wondering if there is a way of changing the USERNAME_FIELD without having to subclass the AbstractUser. I saw in this

File field not passing data to form

我与影子孤独终老i 提交于 2019-11-29 16:46:22
I am using python 2.7 & django 1.5 Forms.py class FileUploadForm( forms.Form ): file = forms.FileField() title = forms.CharField(max_length = 200) HTML <form action="{% url 'upload_file' %}" method="post" class="userFroms"> {% csrf_token %} <ul class="pull-left"> <li> <div class="formLabel ">Title</div> <div class="formFields"><input name="title" type="text" /> </div> </li> <li> <div class="formLabel">Upload File</div> <div class="formFields"> <input name="file" type="file" size="20" /> </div> </li> </ul> <p align="center" style="margin:20px 0; "><input type="submit" value="submit" class="btn

Django Query sort case-insensitive using Model method with PostgreSQL

若如初见. 提交于 2019-11-29 10:58:14
I'm really new to django, python and postgres... I can't seem to find the answer on how to order_by being case insensitive while using Model as the query method, only if you use direct SQL queries. Model @classmethod def get_channel_list(cls, account): return cls.objects.filter(accountid=account).order_by('-name').values_list('name', 'channelid') Data set and order it's currently being ordered in test b test a test channel a test channel a test 2 a b test Test Channel Test 3 Test 3 Test 2 Channel any help would be much appreciated. Using QuerySet.extra(select=...) : @classmethod def get

Using email as username field in Django 1.5 custom User model results in FieldError

只愿长相守 提交于 2019-11-28 23:03:50
I want to use an email field as the username field for my custom user model. I have the following custom User model subclassing Django's AbstractUser model: class CustomUser(AbstractUser): .... email = models.EmailField(max_length=255, unique=True) USERNAME_FIELD = 'email' But when I run python manage.py sql myapp I get the following error: FieldError: Local field 'email' in class 'CustomUser' clashes with field of similar name from base class 'AbstractUser' The reason I include my own email field in the first place is to add the unique=True option to it. otherwise I get: myapp.customuser: The