Using this section of the Master Class notes found here

http://toys.jacobian.org/presentations/2007/oscon/tutorial/#s103

I've been working to create a custom field-type for consolidating
some of my work that was previously duplicated across several
models.  The field-type in question is a "PartialDateField" in
which pieces of the date can be missing, or the year can be a
range of years (good for date-of-[birth|death] fields).  Thus, my
plan is to have something like

  class Foo(Model):
    dob = PartialDateField()

which then creates "dob_month", "dob_day", "dob_min_year" and
"dob_max_year" fields.  Bits and pieces can be absent, so you
might know that a person's birthday month/day, but not the year;
or you might know that the person is between 25-30 years old; or
you might have an exact date, in which case the min/max year are
the same and the month/day fields are populated.

Since this code is shared across multiple apps in my project, it
seems like it should be put in some file like myproj/fields.py so
it can be shared by myproj/myapp1 and myproj/myapp2 correct?

I'd like to build some automated tests as I go along, but I'm not
sure how to go about building a test harness that creates a
temporary model with my field-type, creates a table in the DB
with that field in it, and then performs operations on that table.

I know how to go about dynamically creating a model, but then I
need to syncdb on that model, test it, and then drop/truncate the
test table.

I'd also like to be able to do comparisons of these
PartialDateFields on the DB side of things, having them
translated to their appropriate corresponding code (for the __lt,
__gt, __between, __range, etc bits).  Thus, it would be nice to
be able to write code like

  foos = Foo.objects.filter(dob__gt = date(1955,1,1))

So in summary:

1) where is the best place to put shared custom Fields?
2) how do I write tests to test this Field class?
3) is there a way for a Field subclass to tweak the behavior of
the __lt/__gt family of operators to generate the right code to
be sent to a DB?

Thanks,

-tim





--~--~---------~--~----~------------~-------~--~----~
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?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to