Question

As all of you know django provides a very basic though flexible admin panel for your project. I've seen here discussions refering the (dis)advantages. of writing your own control interface and using the default one. Just for recapitulation I'll mention that, imo, django.contrib.admin is for quick and simple projects that does not require any complex content managment; so for the absolute control and full customization of a site one probably should implement an adequate administration interface.

I want to try roll my own admin for the project I'm working on, but really don't want to reinvet the wheel, so maybe I could use the django's admin as a plugged app in my project customizing it the way I want to? Do you have any ideas of how can it be done? Maybe there already are some simmilar apps?

Was it helpful?

Solution

I don't have any advice for django.contrib.admin since I don't use it. My clients prefer an almost CMS-like inline updating of their site (two "versions" confuses them) and I prefer the extra control.

So, on that vein, have you ever used django.forms? Django forms will give you an easy way to accept and validate input as per your needs. You can extend a form with your own custom fields, and customise their validation. So for example you can add a field to a form that raises a ValidationError if the inputted string contains characters you want to omit, for example. Django has a lot of useful input fields, including EmailField.

The next really big trick is the django.forms.ModelForm. This provides a very easy way to shortcut writing a custom form and then inserting that into the right object then saving that into the database. It does it for you. All of it. Literally, you do this:

fItem = ItemForm(request.POST) 
# or
# I = Item.objects.get(id=?)
# fItem = ItemForm(request.POST, instance=I) 

if f.is_valid():
    fItem.save()

From that and using forms, you can create CRUD operations yourself very easily.

The next thing to achieve is users, groups and permissions. There's nothing stopping you using the provided authentication stuff for this and providing your own UI. You don't have to use the actual admin site as well; the two aren't tied together.

I personally rolled my own which I tend to use, because on one of my jobs the client had specific requirements for authentication and authorization. I wouldn't recommend it though - just use what's there. Especially since there are now authentication backends such as Django-SocialAuth.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top