How will the model be used? It looks to me like what you're after is
the 'editable' parameter, as in something like:
class Unclassified(models.Model):
  name = models.CharField(max_length=50)
  cost = models.DecimalField(max_digits=5,decimal_places=2)

class Classified(Unclassified):
  name =
models.CharField(default="Hotels",editable=False,max_length=50)

class Fixed(Unclassified):
  name = models.Charfield(editable=False,max_length=50)
  cost =
models.DecimalField(max_digits=5,decimal_places=2,editable=False)

On Mar 16, 9:36 am, ALJ <astley.lejas...@gmail.com> wrote:
> Hi Preston,
>
> Sorry, I don't get it.
>
> The certainly do have the same fields, but sometimes the fields are
> derived from a linked table, or are a foreign key or sometimes text.
> So I don't understand how having the interface adapt to what the
> current type is would work.
>
> ALJ
>
> On Mar 16, 3:04 pm, Preston Holmes <pres...@ptone.com> wrote:
>
> > On Mar 16, 3:21 am, ALJ <astley.lejas...@gmail.com> wrote:
>
> > > This is a bit of a modeling question that I am struggling to get my
> > > head around. How would you model this scenario?
>
> > > I have to record expenses that are of 3 different types.
>
> > > 1. Fixed - The name of the expense and unit amount are fixed. For
> > > example, "inconvenience allowance" of £30 per day.
> > > 2. Classified - The name of the expense is fixed, but the actual unit
> > > amount isn't. For example "Hotel expenses". The actual unit amount
> > > will depend on the hotel they stay at. They'll need to enter that
> > > themselves.
> > > 3. Unclassified - The name of the expense and the amount is arbitrary.
> > > So they may have an expense we haven't thought of before but it needs
> > > to go in.
>
> > > Of course I'll need to create a summary that tots up the total
> > > expenses for the particular event.
>
> > whether you subclass a base model, or simply have a "type" field on
> > your expense object is going to depend on the details and nuance of
> > the rest of your business logic in your app.  I would only say that
> > simple is better unless you have a reason or need for the complexity.
>
> > Given that the fields between them are identical, I would probably
> > just use a "type" choice field and have the interface adapt as needed.
>
> > -Preston
>
> > > Would the best way of doing this be:
>
> > > a) Have a base model and then build on that for the 3 different
> > > scenarios?
> > > b) Have three different tables and then do a union on them?
>
> > > Just for interest ... this is where I got so far, but am now stumped
>
> > > class CostType(models.Model):
> > >     name = models.CharField("Name", max_length=30) 'e.g. commission,
> > > subsistence ...
>
> > > class CostItem(models.Model):
> > >     name = models.CharField("Name", max_length=50) 'e.g. product x,
> > > inconvenience allowance, ...
> > >     cost_type = models.ForeignKey(CostType, verbose_name="Type")
>
> > > class Rate(models.Model):
> > >     cost_item = models.ForeignKey(CostItem, verbose_name="Item")
> > >     valid_from = models.DateField("From")
> > >     valid_till = models.DateField("Till")
> > >     unit_amount = models.DecimalField("Price Per Unit", max_digits=5,
> > > decimal_places=2)
>
> > > 'Costs with a fixed description and unit amount
> > > class FixedCostList(models.Model):
> > >     markettingevent= models.ForeignKey(Event)
> > >     rate = models.ForeignKey(Rate)
> > >     units = models.IntegerField()
>
> > > 'Costs with a fixed description but arbitrary amount
> > > class StructuredCostList(models.Model):
> > >     markettingevent= models.ForeignKey(Event)
> > >     cost_item = models.ForeignKey(CostItem, verbose_name="Item")
> > >     unit_amount = models.DecimalField("Price Per Unit", max_digits=5,
> > > decimal_places=2)
> > >     units = models.IntegerField()
>
> > > 'Costs with both a arbitrary description and amount
> > > class OtherCostList(models.Model):
> > >     markettingevent= models.ForeignKey(Event)
> > >     description = models.CharField("Name", max_length=30)
> > >     unit_amount = models.DecimalField("Price Per Unit", max_digits=5,
> > > decimal_places=2)
> > >     units = models.IntegerField()

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.

Reply via email to