hi,

i'd like to know your opinion about a decision i have to make a lot of 
times while developing with django...

an example:

let's have a system where sometimes we have to send out a LOT of emails.
so we decide to have a periodically running process (cronjob, probably), 
that will check whether there is some mail-sending to do, and if yes, 
will send it out.

let's have the following model:

======================================================

class Task(Model):
        begin = DateTime(blank=True,null=True)
        end = DateTime(blank=True,null=True)

        from_addr = EmailField()
        subject = CharField(maxlength=100)
        body = TextField()

        #these are the important fields
        all_recipients = IntegerField()
        remaining_recipients = IntegerField()
        error_count = IntegerField()

        

class Recipient(Model):
        addr = EmailField()
        task = ForeignKey(Task)
        done = BooleanField(default=False)
        error = CharField(maxlength=100,blank=True)


(if the error-field is an empty string, that means that there were no 
errors)
======================================================


i hope the models are understandable... the mails are sent with the same 
from_addr, subject and body, but to a lot of different recipients.

now please look at the last 3 fields in the Task model. they are clearly 
redundant. they can be easily calculated from the Recipient objects.
so theoretically we could drop those fields (we could even create 
read-only attributes in the Task-model, which would query those values 
in the db)



now imagine a webpage, where i want to list the status of all the Tasks...

one line for every task, and i'd like to show all those numbers for it.
and i do not want to do 3 separate db-queries for every Task object (to 
calculate those "missing-because-redundant" fields)


with custom SQL, i could do it in a constant-number of queries, but not 
with django querysets.

so, i have 2 possibilities:

1. i remove those 3 fields from the Task model (because they are 
redundant), and use a few custom sql-queries in the task-list-view

or

2. i keep those 3 fields, i ignore that they are redundant, and 
everything works nicely with querysets.


which way do you chose-usually/recommend?

p.s: i hope you understand that this is not a critique of django. this 
would happen with any non-native-sql db-api.

thanks,
gabor

--~--~---------~--~----~------------~-------~--~----~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users
-~----------~----~----~----~------~----~------~--~---

Reply via email to