On Sat, May 9, 2015 at 4:10 AM, charles javelona
<charlesjavel...@gmail.com> wrote:
> Hi there,
>
> I am a newbie in Django. My goal is to create an online platform exchange
> for my community that helps students like me get part-time jobs from
> employers.
> For the past days, I taught myself how to build a blog and the polls app,
> but it seems what I am building is more complex than a regular tutorial.
>
> My first few obstacles are the following:
>   - Registering and authenticating two types of users, Employers and
> Students.
>   - Logging two the two types of users.
>   - How would I even start defining the models for this?
>
>
> Here is my first attempt of defining them.
> from django.db import models
>
> class User(models.Model):
> created_at = models.DateTimeField(auto_now_add=True)
> email = models.EmailField(max_length=254, unique=True)
> first_name = models.CharField(max_length=30)
> last_name = models.CharField(max_length=30)
> mobile = models.CharField(max_length=12)
> password = models.CharField(max_length=100, null=True)
>
> def __str__(self):
> return self.email
>
> class Meta:
> abstract = True
>
>
> class Student(User):
> school = models.CharField(max_length=40)
>
>
> class Employer(User):
> company = models.CharField(max_length=40)
>
>
> Can someone please guide me in the right direction? I am fairly confuse and
> I do not want to abstract too much of the code because I want to truly
> understand how the Django architecure works.
> If you need more information, feel free to ask me and I would be happy to
> clarify things.
>
> Thanks a bunch!
> Charles

I would simplify things, have just one type of user, who can be
associated with 1:N companies and 1:N schools. A user is an employer
if they are associated with at least one company, and a user is a
student if they are associated with at least one school.

You could denormalise the relationship with attributes on the user
model if/when you are worried about performance.

Eg:

class Company(models.Model):
  name = ...
  contact_details = ...

class School(models.Model):
  name = ....

class User(models.Model):
  ...
  company = models.ManyToManyField(Company)
  school = models.ManytoManyField(School)


You could expand things about the relationship by adding a information
to the join (or "through") table; perhaps you might want to record
when a student started/left a school; this would also allow you to
record which employers are alumni of a school:

https://docs.djangoproject.com/en/1.8/topics/db/models/#intermediary-manytomany

Cheers

Tom

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAFHbX1KUBq5KAV50f%2Bxk0vzuxAsb7hLC5BNht_p6Vu8L3bgucA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to