4👍
✅
You could try this:
class UserProfile(models.Model):
user = models.ForeignKey(User)
#define general fields
class Freelancer(models.Model):
profile = models.ForeignKey(UserProfile)
#freelancer specific fields
class Meta:
db_table = 'freelancer'
class Customers(models.Model):
profile = models.ForeignKey(UserProfile)
#customer specific fields
class Meta:
db_table = 'customer'
You can then have as many Users as you want from the UserProfile.
5👍
You should need just use Groups Django mechanism – you need to create two groups freelancer
and let say common
and check whether user is in first or second group – then show him appropriate view
To check whether user is in group you can use
User.objects.filter(pk=userId, groups__name='freelancer').exists()
- [Django]-Django ManyToMany field returns None but it has related records
- [Django]-Django Rest Framework: XMLHttpRequest cannot load http://127.0.0.1:8000/xyz/api/abc
- [Django]-Django – Save modelForm even if no field are changed on POST
- [Django]-How to run python script inside django project?
1👍
You Could Try extending the Default Django Auth User like this
Create an App with Account or Whatever name you like , then in models.py write like below
class User(AbstractUser):
is_head = models.BooleanField(default=False)
is_staff = models.BooleanField(default=False)
is_public = models.BooleanField(default=False)
Add Auth Extended Model in Settings.py
AUTH_USER_MODEL = 'accounts.User'
Migrate your Account app and you are all set with Your User Extended Model.
- [Django]-Django 1.9: Should I avoid importing models during `django.setup()`?
- [Django]-Using Twisted for asynchronous file uploads from Django app
- [Django]-Django app not found despite adding to INSTALLED_APPS?
- [Django]-Can't get proper response from `issubclass()` when called with Django's `__fake__` model type inside migration
- [Django]-Django: celery task does not execute with .delay()
Source:stackexchange.com