[Answered ]-Can I use the django admin as an app?

2đź‘Ť

âś…

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.

👤user257111

Leave a comment