English 中文(简体)
如何为表格撰写习惯节选方法,以在不同的表格中增加数据?
原标题:How to write a custom save method for a table to add data to a different table?
  • 时间:2011-05-06 22:05:34
  •  标签:
  • django

I am very new to django. I am trying to implement small application for my business which is a rental service for a football field which is made of artificial grass. Service is based on hourly rental of the field. People can rent the field hourly or they can chose membership option which includes specific day and hour in a week for a defined period. I have two classes in my model.

一项是一次性保留。 人民可以在一周内将足球场保留一天和小时。 这非常简单。

class Reservation(models.Model):
    name = models.ForeignKey(User)
    membership = models.ForeignKey((Member), blank=True, null=True, editable=False)
    date = models.DateField()
    field_name = models.ForeignKey(Field)
    fee = models.DecimalField(decimal_places=0, max_digits=3)
    is_member = models.BooleanField(default=False, editable=False)
    is_active = models.BooleanField(default=True)

    def __unicode__(self):
        return u %s %s %s %s  % (self.date, self.user.first_name,self.user.last_name, self.field)

    class Meta:
        unique_together = (("date", "field"))

另一位成员。 人民可以申请成为成员。 当有人申请船舶时,即在船舶起步和起步之间,要自动设定对该日及时间段的保留,因此,当天和时间不会有任何一次性保留。 我需要书写一种习俗,但我无法找到如何在保留表中增加信息,同时节省成员席位。 我想增加成员名称,使成员成为真正的成员,以确保其为成员保留。

class Member(models.Model):
    DAY_CHOICES = (
        (1,  PAZARTESI ),
        (2,  SALI ),
        (3,  CARSAMBA ),
        (4,  PERSEMBE ),
        (5,  CUMA ),
        (6 , CUMARTESI ),
        (7,  PAZAR ),
    )
    name = models.ForeignKey(User)
    starting_date = models.DateField()
    end_date = models.DateField()
    day = models.IntegerField(max_length=1, choices=GUN_CHOICES)
    field = models.ForeignKey(Field)
    fee = models.DecimalField(decimal_places=0, max_digits=3)

    def __unicode__(self):
        return u %s %s, %s, %s  % (self.name.first_name, self.name.last_name, self.day, self.field)

    class Meta:
        unique_together = (( date ,  field ))

请你帮助吗?

感谢。

问题回答




相关问题
How to get two random records with Django

How do I get two distinct random records using Django? I ve seen questions about how to get one but I need to get two random records and they must differ.

Moving (very old) Zope/Plone Site to Django

I am ask to move data from a (now offline) site driven by Plone to a new Django site. These are the version informations I have: Zope Version (unreleased version, python 2.1.3 ) Python Version 2.1....

Can Django models use MySQL functions?

Is there a way to force Django models to pass a field to a MySQL function every time the model data is read or loaded? To clarify what I mean in SQL, I want the Django model to produce something like ...

Flexible pagination in Django

I d like to implement pagination such that I can allow the user to choose the number of records per page such as 10, 25, 50 etc. How should I go about this? Is there an app I can add onto my project ...

is it convenient to urlencode all next parameters? - django

While writing code, it is pretty common to request a page with an appended "next" query string argument. For instance, in the following template code next points back to the page the user is on: &...

Pragmatically adding give-aways/freebies to an online store

Our business currently has an online store and recently we ve been offering free specials to our customers. Right now, we simply display the special and give the buyer a notice stating we will add the ...

热门标签