from django.db import models
from django.utils.translation import ugettext_lazy as _
from django.contrib.auth.models import User as DjangoUser

class UserManager(models.Manager):
    """
    Automatically applies select_related on the User model so its expenses are selected too
    """
    def get_query_set(self):
        return super(UserManager, self).get_query_set().select_related('expenses')

class User(DjangoUser):
    """
    Extends the default User model to add expense-related functionnality
    """
    objects = UserManager()

    class Meta:
        proxy = True

class Group(models.Model):
    """
    A group is a number of person sharing expenses for a particular purpose
    """
    name = models.CharField(verbose_name=_('Name'), max_length=255)
    users = models.ManyToManyField(User, verbose_name=_('User'), related_name='groups', through='Membership')

class Membership(models.Model):
    user = models.ForeignKey(User)
    group = models.ForeignKey(Group)
    date_joined = models.DateField(verbose_name=_('Date joined'))

class Expense(models.Model):
    """
    A basic expense. Each expense is made by one user, and is added to the user's total expenses, or "Karma"
    """
    title = models.CharField(verbose_name=_('Title'), max_length=255)
    description = models.TextField(verbose_name=_('Description'), blank=True)
    date = models.DateField(auto_now_add=True, verbose_name=_('Date'))
    buyer = models.ForeignKey(User, verbose_name=_('Buyer'), related_name='expenses')
    group = models.ForeignKey(Group, verbose_name=_('Group'), related_name='expenses')
    
    class Meta:
        ordering = ['-date',]
        get_latest_by = 'date'
        verbose_name = _('Expense')
        verbose_name_plural = _('Expenses')

class Expense_Shares(models.Model):
    """
    A share of a expense is a part of it's total value, attributed to a user
    """
    amount = models.DecimalField(max_digits=7, decimal_places=2, verbose_name=_('Amount'))
    expense = models.ForeignKey(Expense, verbose_name=_('Expense'), related_name='shares')
    user = models.ForeignKey(User, verbose_name=_('User'), related_name='expense_shares')
52c821893f2b31d25b3bd70a9bb9cc97b0e2c753
<mask token>


class Expense(models.Model):
    """
    A basic expense. Each expense is made by one user, and is added to the user's total expenses, or "Karma"
    """
    title = models.CharField(verbose_name=_('Title'), max_length=255)
    description = models.TextField(verbose_name=_('Description'), blank=True)
    date = models.DateField(auto_now_add=True, verbose_name=_('Date'))
    buyer = models.ForeignKey(User, verbose_name=_('Buyer'), related_name=
        'expenses')
    group = models.ForeignKey(Group, verbose_name=_('Group'), related_name=
        'expenses')


    class Meta:
        ordering = ['-date']
        get_latest_by = 'date'
        verbose_name = _('Expense')
        verbose_name_plural = _('Expenses')


class Expense_Shares(models.Model):
    """
    A share of a expense is a part of it's total value, attributed to a user
    """
    amount = models.DecimalField(max_digits=7, decimal_places=2,
        verbose_name=_('Amount'))
    expense = models.ForeignKey(Expense, verbose_name=_('Expense'),
        related_name='shares')
    user = models.ForeignKey(User, verbose_name=_('User'), related_name=
        'expense_shares')

<mask token>


class Group(models.Model):
    <mask token>
    <mask token>
    <mask token>


class Membership(models.Model):
    user = models.ForeignKey(User)
    group = models.ForeignKey(Group)
    date_joined = models.DateField(verbose_name=_('Date joined'))


class Expense(models.Model):
    """
    A basic expense. Each expense is made by one user, and is added to the user's total expenses, or "Karma"
    """
    title = models.CharField(verbose_name=_('Title'), max_length=255)
    description = models.TextField(verbose_name=_('Description'), blank=True)
    date = models.DateField(auto_now_add=True, verbose_name=_('Date'))
    buyer = models.ForeignKey(User, verbose_name=_('Buyer'), related_name=
        'expenses')
    group = models.ForeignKey(Group, verbose_name=_('Group'), related_name=
        'expenses')


    class Meta:
        ordering = ['-date']
        get_latest_by = 'date'
        verbose_name = _('Expense')
        verbose_name_plural = _('Expenses')


class Expense_Shares(models.Model):
    """
    A share of a expense is a part of it's total value, attributed to a user
    """
    amount = models.DecimalField(max_digits=7, decimal_places=2,
        verbose_name=_('Amount'))
    expense = models.ForeignKey(Expense, verbose_name=_('Expense'),
        related_name='shares')
    user = models.ForeignKey(User, verbose_name=_('User'), related_name=
        'expense_shares')

<mask token>


class User(DjangoUser):
    """
    Extends the default User model to add expense-related functionnality
    """
    objects = UserManager()


    class Meta:
        proxy = True


class Group(models.Model):
    """
    A group is a number of person sharing expenses for a particular purpose
    """
    name = models.CharField(verbose_name=_('Name'), max_length=255)
    users = models.ManyToManyField(User, verbose_name=_('User'),
        related_name='groups', through='Membership')


class Membership(models.Model):
    user = models.ForeignKey(User)
    group = models.ForeignKey(Group)
    date_joined = models.DateField(verbose_name=_('Date joined'))


class Expense(models.Model):
    """
    A basic expense. Each expense is made by one user, and is added to the user's total expenses, or "Karma"
    """
    title = models.CharField(verbose_name=_('Title'), max_length=255)
    description = models.TextField(verbose_name=_('Description'), blank=True)
    date = models.DateField(auto_now_add=True, verbose_name=_('Date'))
    buyer = models.ForeignKey(User, verbose_name=_('Buyer'), related_name=
        'expenses')
    group = models.ForeignKey(Group, verbose_name=_('Group'), related_name=
        'expenses')


    class Meta:
        ordering = ['-date']
        get_latest_by = 'date'
        verbose_name = _('Expense')
        verbose_name_plural = _('Expenses')


class Expense_Shares(models.Model):
    """
    A share of a expense is a part of it's total value, attributed to a user
    """
    amount = models.DecimalField(max_digits=7, decimal_places=2,
        verbose_name=_('Amount'))
    expense = models.ForeignKey(Expense, verbose_name=_('Expense'),
        related_name='shares')
    user = models.ForeignKey(User, verbose_name=_('User'), related_name=
        'expense_shares')

<mask token>


class UserManager(models.Manager):
    <mask token>
    <mask token>


class User(DjangoUser):
    """
    Extends the default User model to add expense-related functionnality
    """
    objects = UserManager()


    class Meta:
        proxy = True


class Group(models.Model):
    """
    A group is a number of person sharing expenses for a particular purpose
    """
    name = models.CharField(verbose_name=_('Name'), max_length=255)
    users = models.ManyToManyField(User, verbose_name=_('User'),
        related_name='groups', through='Membership')


class Membership(models.Model):
    user = models.ForeignKey(User)
    group = models.ForeignKey(Group)
    date_joined = models.DateField(verbose_name=_('Date joined'))


class Expense(models.Model):
    """
    A basic expense. Each expense is made by one user, and is added to the user's total expenses, or "Karma"
    """
    title = models.CharField(verbose_name=_('Title'), max_length=255)
    description = models.TextField(verbose_name=_('Description'), blank=True)
    date = models.DateField(auto_now_add=True, verbose_name=_('Date'))
    buyer = models.ForeignKey(User, verbose_name=_('Buyer'), related_name=
        'expenses')
    group = models.ForeignKey(Group, verbose_name=_('Group'), related_name=
        'expenses')


    class Meta:
        ordering = ['-date']
        get_latest_by = 'date'
        verbose_name = _('Expense')
        verbose_name_plural = _('Expenses')


class Expense_Shares(models.Model):
    """
    A share of a expense is a part of it's total value, attributed to a user
    """
    amount = models.DecimalField(max_digits=7, decimal_places=2,
        verbose_name=_('Amount'))
    expense = models.ForeignKey(Expense, verbose_name=_('Expense'),
        related_name='shares')
    user = models.ForeignKey(User, verbose_name=_('User'), related_name=
        'expense_shares')

from django.db import models
from django.utils.translation import ugettext_lazy as _
from django.contrib.auth.models import User as DjangoUser

class UserManager(models.Manager):
    """
    Automatically applies select_related on the User model so its expenses are selected too
    """
    def get_query_set(self):
        return super(UserManager, self).get_query_set().select_related('expenses')

class User(DjangoUser):
    """
    Extends the default User model to add expense-related functionnality
    """
    objects = UserManager()

    class Meta:
        proxy = True

class Group(models.Model):
    """
    A group is a number of person sharing expenses for a particular purpose
    """
    name = models.CharField(verbose_name=_('Name'), max_length=255)
    users = models.ManyToManyField(User, verbose_name=_('User'), related_name='groups', through='Membership')

class Membership(models.Model):
    user = models.ForeignKey(User)
    group = models.ForeignKey(Group)
    date_joined = models.DateField(verbose_name=_('Date joined'))

class Expense(models.Model):
    """
    A basic expense. Each expense is made by one user, and is added to the user's total expenses, or "Karma"
    """
    title = models.CharField(verbose_name=_('Title'), max_length=255)
    description = models.TextField(verbose_name=_('Description'), blank=True)
    date = models.DateField(auto_now_add=True, verbose_name=_('Date'))
    buyer = models.ForeignKey(User, verbose_name=_('Buyer'), related_name='expenses')
    group = models.ForeignKey(Group, verbose_name=_('Group'), related_name='expenses')
    
    class Meta:
        ordering = ['-date',]
        get_latest_by = 'date'
        verbose_name = _('Expense')
        verbose_name_plural = _('Expenses')

class Expense_Shares(models.Model):
    """
    A share of a expense is a part of it's total value, attributed to a user
    """
    amount = models.DecimalField(max_digits=7, decimal_places=2, verbose_name=_('Amount'))
    expense = models.ForeignKey(Expense, verbose_name=_('Expense'), related_name='shares')
    user = models.ForeignKey(User, verbose_name=_('User'), related_name='expense_shares')