OK So these are UI issues and how you are saving Users to the
database.  The database field itself is a CharField.

1.) To hide form elements add a tupple inside the FormField under
class meta like so:
class CasUserForm(ModelForm):

exclude = [field1, field2]

2.)

On Dec 16, 6:39 am, Reino <re...@oribium.se> wrote:
> I am new to Django, and I am building a simple application where I am
> going to manage a legacy user database from Djangos admin interface.
> Below is how my model looks like.
>
> My goal is to hide some of the fields in the form where I edit/add
> users. However, currently I can see all the fields except from the Id
> field. Furhermore, the password field is stored in clear text, but is
> supposed to be stored as an md5 hash, and the password is visible in
> clear text in the form. Any hints what I am doing wrong, and how to
> improve things?
>
> from django.db import models
> from django.contrib import admin
> from django.forms import ModelForm, PasswordInput
>
> import datetime
> try:
>         from hashlib import md5
> except:
>         from md5 import new as md5
>
> class CasDomain(models.Model):
>         name = models.CharField(max_length=64, primary_key=True)
>         class Meta:
>                 db_table = u'cas_domain'
>
>         def __unicode__(self):
>                 return self.name
>
> class CasUser(models.Model):
>         ACCESS_LEVEL = (
>         (0, 'Administrator'),
>         (1, 'Manager'),
>         (2, 'Domain Manager'),
>         (3, 'Email'),
>         (255, 'None'),
>         )
>
>         id = models.AutoField(primary_key=True)
>         username = models.CharField(max_length=64)
>         password = models.CharField(max_length=32)
>         email = models.EmailField()
>         first_name = models.CharField(max_length=64, blank=True)
>         last_name = models.CharField(max_length=64, blank=True)
>         froxlor_mail_id = models.IntegerField(null=True, blank=True)
>         access_level = models.IntegerField(choices=ACCESS_LEVEL)
>         domain = models.ForeignKey(CasDomain,db_column='domain')
>         mod_date = models.DateField()
>         pub_date = models.DateField()
>         class Meta:
>                 db_table = u'cas_user'
>
>         def __unicode__(self):
>                 return self.username
>
>         def __unicode__(self):
>                 return self.password
>
>         def __unicode__(self):
>                 return self.first_name
>
>         def __unicode__(self):
>                 return self.last_name
>
> class CasUserForm(ModelForm):
>         class Meta:
>                 model = CasUser
>                 fields = ('username', 'first_name', 'first_name', 'email',
> 'access_level')
>                 widgets = {
>                         'password': PasswordInput(),
>                 }
>
>         def save(self):
>                 if not self.id:
>                         self.pub_date = datetime.date.today()
>                         self.password = md5(self.password).hexdigest()
>                 self.mod_date = datetime.datetime.today()
>                 super(CasUserForm, self).save()
>
> class CasUserAdmin(admin.ModelAdmin):
>         class Meta:
>                 form = CasUserForm
>
> # Make sure the classes are available in the admin interface
> admin.site.register(CasDomain)
> admin.site.register(CasUser, CasUserAdmin)

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.

Reply via email to