Electronics & Programming

develissimo

Open Source electronics development and programming

  • You are not logged in.

#1 Jan. 16, 2011 22:10:54

m.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

Thinking to change my db schema


I'm building a web app with django. It uses postgresql. The app code
is getting really messy and I'd like to improve it(my begginer skills
being a big factor too).

This is an excerpt of my models.py file:

REPEATS_CHOICES = (
(NEVER, 'Never'),
(DAILY, 'Daily'),
(WEEKLY, 'Weekly'),
(MONTHLY, 'Monthly'),
...some more...
)

class Transaction(models.Model):
name = models.CharField(max_length=30)
type = models.IntegerField(max_length=1, choices=TYPE_CHOICES) # 0
= 'Income' , 1 = 'Expense'
amount = models.DecimalField(max_digits=12, decimal_places=2)
date = models.DateField(default=date.today)
frequency = models.IntegerField(max_length=2,
choices=REPEATS_CHOICES)
ends = models.DateField(blank=True, null=True)
active = models.BooleanField(default=True)
category = models.ForeignKey(Category,
related_name='transactions', blank=True, null=True)
account = models.ForeignKey(Account, related_name='transactions')

The problem is with date, frequency and ends. With this info I can
know all the dates in which transactions occurs and use it to fill a
cashflow table. Doing things this way involves creating a lot of
structures(dictionaries, lists and tuples) and iterating them a lot.
Maybe there is a very simple way of solving this with the actual
schema, but I couldn't realize how.

I think that the app would be easier to code if, at the creation of a
transaction, I could save all the dates in the db. I don't know if
it's possible or if it's a good idea.

Possible solutions:

-I'm reading a book about google app engine and the datastore's
multivalued properties. What do you think about this for solving my
problem?.

-I didn't know about the PickleField. I'm now reading about it, maybe
I could use it to store all the transaction's datetime objects.

--
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+unsubscr...@googlegroups.com.
For more options, visit this group athttp://groups.google.com/group/django-users?hl=en.

Offline

#2 Jan. 17, 2011 00:03:56

Konrad D.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

Thinking to change my db schema


> -I didn't know about the PickleField. I'm now reading about it, maybe
> I could use it to store all the transaction's datetime objects.

I'm using PickleField for precomputing some values, that I'd like to
keep normalized as well. Found no problems with this approach so far.
You can implement re-computing the values in the after_save signal.

Konrad

--
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+unsubscr...@googlegroups.com.
For more options, visit this group athttp://groups.google.com/group/django-users?hl=en.

Offline

#3 Jan. 17, 2011 11:17:55

Dan F.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

Thinking to change my db schema


Hi,

> The problem is with date, frequency and ends. With this info I can
> know all the dates in which transactions occurs and use it to fill a
> cashflow table. Doing things this way involves creating a lot of
> structures(dictionaries, lists and tuples) and iterating them a lot.
> Maybe there is a very simple way of solving this with the actual
> schema, but I couldn't realize how.
>
> I think that the app would be easier to code if, at the creation of a
> transaction, I could save all the dates in the db. I don't know if
> it's possible or if it's a good idea.

You might want to look at python-dateutil, which lets you model repeating
events.http://niemeyer.net/python-dateutilFor Django, you might find that glamkit-eventtools is worth a look. I've used
it to model holiday/vacation departure information for a travel site. You might
find inspiration in its approach, even if you can't use it directly.

Cheers,
Dan
--
Dan Fairs | dan.fa...@gmail.com | www.fezconsulting.com


--
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+unsubscr...@googlegroups.com.
For more options, visit this group athttp://groups.google.com/group/django-users?hl=en.

Offline

Board footer

Moderator control

Enjoy the 21st of October
PoweredBy

The Forums are managed by develissimo stuff members, if you find any issues or misplaced content please help us to fix it. Thank you! Tell us via Contact Options
Leave a Message
Welcome to Develissimo Live Support