Code: Alles auswählen
from django.contrib.auth.models import User
class UsernameForm(forms.ModelForm):
class Meta:
model = User
fields=("username",)
Weiß jemand warum?User with this Username already exists.
Code: Alles auswählen
from django.contrib.auth.models import User
class UsernameForm(forms.ModelForm):
class Meta:
model = User
fields=("username",)
Weiß jemand warum?User with this Username already exists.
Code: Alles auswählen
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import os
os.chdir("../pylucid_project/") # Goto where django exist, optional
APP_LABEL = os.path.splitext(os.path.basename(__file__))[0]
os.environ["DJANGO_SETTINGS_MODULE"] = "django.conf.global_settings"
from django.conf import global_settings
global_settings.INSTALLED_APPS = (
'django.contrib.auth',
'django.contrib.contenttypes',
APP_LABEL,
)
global_settings.DATABASE_ENGINE = "sqlite3"
global_settings.DATABASE_NAME = ":memory:"
#______________________________________________________________________________
# Test app code:
from django import forms
from django.contrib.auth.models import User
class UsernameForm(forms.ModelForm):
class Meta:
model = User
fields=("username",)
#------------------------------------------------------------------------------
if __name__ == "__main__":
print "- create the model tables...",
from django.core import management
management.call_command('syncdb', verbosity=1, interactive=False)
print "OK"
#__________________________________________________________________________
# Test code:
User.objects.create_superuser(username="test", email="", password="test")
f = UsernameForm({u'username': u'test'})
print f.is_valid()
print f.errors
print "- END -"
Es ist also so, das es normal ist?...
False
...User with this Username already exists...
...
Code: Alles auswählen
class UsernameForm(forms.ModelForm):
def validate_unique(self):
""" nicht unique testen """
pass
class Meta:
model = User
fields=("username",)
Use the source luke! Sollte nach anschauen von ModelForm.clean eigentlich glasklar sein… Allerdings musst du probieren, ob die max_length dann nicht auch gleich übersprungen wird…jens hat geschrieben:Wenn ich eine ModelForm erstelle, dann schon. Aber wie deaktiviere ich die model validation da?