<bruno.desthuilliers@gmail.com> wrote:
> On Jun 29, 7:32 pm, Kyle Latham <kly.lat...@gmail.com> wrote:
> (snip)
>> I have no idea what is going wrong, but here is all my code thus far
>> (I'm following the tutorial to create my own app that will display
>> various material measurements)
>>
>> -----------------------------------------------
>> models.py
>> -----------------------------------------------
>> from django.db import models
>>
>> # Create your models here.
>> class adhesive(models.Model):
>> measurement_id = models.CharField(max_length = 200)
>> material_id = models.CharField(max_length = 200)
>> program_name = models.CharField(max_length = 200)
>> date = models.DateField()
>> measurement_method = models.CharField(max_length = 30)
>> frequency_low = models.IntegerField()
>> frequency_high = models.IntegerField()
>>
>> class ceramic(models.Model):
>> measurement_id = models.CharField(max_length = 200)
>> material_id = models.CharField(max_length = 200)
>> program_name = models.CharField(max_length = 200)
>> date = models.DateField()
>> measurement_method = models.CharField(max_length = 30)
>> frequency_low = models.IntegerField()
>> frequency_high = models.IntegerField()
>>
>> class composite(models.Model):
>> measurement_id = models.CharField(max_length = 200)
>> material_id = models.CharField(max_length = 200)
>> program_name = models.CharField(max_length = 200)
>> date = models.DateField()
>> measurement_method = models.CharField(max_length = 30)
>> frequency_low = models.IntegerField()
>> frequency_high = models.IntegerField()
>>
>
> Totally unrelated to your question, but: why on earth are you creating
> 3 distincs models with the exact same fields ??? You just need one
> single model, and add a "material_type" field (eventually passing in a
> choices list of "Composite", "Ceramic" and "Adhesive").
Another possibility is to make a Material abstract base class, and
have Adhesive, Ceramic, and Composite inherit from it. Or, have a
non-abstract Material base class. Doing either of these things really
only makes sense if you have extra fields to add to the subclasses. I
tend to think doing what Bruno suggests (adding a material type field)
will work better.
Reference; https://docs.djangoproject.com/en/1.3/topics/db/models/#model-inheritance
--
Question the answers
--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
No comments:
Post a Comment