views:

92

answers:

1

Say you have an Events model that contains information about the event. But what about things like slugs, titles and meta description that would go into the html?

It would seem like such things properly belong as attributes to a Page model rather than to an Events model.

Is there a correct way to do this? What are the pros and cons of one approach over the other?

A: 

An Event has some first-class attributes and some "derived" attributes.

Let's focus on Django.

For example, your model might have a big long title and a derived slug.

You can easily define class methods for this derived data.

However, in some cases, you need to denormalize your model to make derived data persistent. In this case, you'll have additional attributes and you'll set those attributes through the save() method.

"Correct" is well-defined -- 3rd Normal Form is correct. You can afford to compute derived fields if they aren't computed all that often. In some cases, you have to break 3NF and persist the data for performance.

S.Lott