views:

330

answers:

1

I currently have three models:

class Request(models.Model):
    requester=models.CharField()
    dateRequested = models.DateField(auto_now=True)
    title= models.CharField(max_length=255)
    description = models.TextField()

class RequestType(models.Model):
    requestType=models.CharField('Request Type', max_length=256)

class RequestTypeInfo(models.Model):
    requestType=models.ForeignKey('RequestType', verbose_name='Request Type')
    title = models.CharField('title', max_length=256)
    info = models.CharField(max_length=256, blank=True)

The idea is that each request shows the information common to all types of requests and additional fields are presented to the users to be filled in depending on the request type selected.

How would I change the models to allow this and how would i write the view to display the form to the user so that the additional information is displayed in-line with the base request. Would it be better to have a second view which asks for the additional information.

The end aim is that the admins can create new request types without creating models in python by just adding a new request and adding any additional info fields.

+1  A: 

So are you saying that you want to create a Many-to-many relationship from Request to RequestTypeInfo using RequestType as your intermediate Model?

class Request(models.Model):
    requester=models.CharField()
    dateRequested = models.DateField(auto_now=True)
    title= models.CharField(max_length=255)
    description = models.TextField()
    request_type = models.ManyToManyField(RequestType, through='RequestTypeInfo')

class RequestType(models.Model):
    requestType=models.CharField('Request Type', max_length=256)

class RequestTypeInfo(models.Model):
    requestType=models.ForeignKey('RequestType', verbose_name='Request Type')
    title = models.CharField('title', max_length=256)
    info = models.CharField(max_length=256, blank=True)

We can talk about inline admin models after this gets clarified.

Pete Karl II