Thanks, Tom. I'm familiar with fixtures. My problem is that I don't know
which fields exactly will be date fields (so I have to check each model for
those fields), and then increment them according to the current date (which
will change every day).

So if a demo happens on the 9th, and my field is set to the 15th, then
tomorrow when I reset the data that field must be set to the 16th (because
the date would now be the 10th). Then on the next day, after the data has
been reset, that field would need to change to be the 17th (because the
current date would be the 11th). Similarly, I'd have to do the same with
every other date in the database, without knowing exactly which fields I
have to change (I only know which "type" of field needs to change), and
without knowing when exactly the database needs to be reset (could be twice
a day, once a day, etc... I can't assume the current date will be different
every time this reset happens).

That's my issue in a nutshell. I will have an initial fixture for the data,
and I'll probably have to store the date the initial fixture (the baseline)
was created. That would give me the appropriate date from which to take a
"delta" (i.e., this field is +5 days, this other field is -41 days, etc).
Then, when the data is reset back to that fixture, I'd have to go through
all the data and find any date, and adjust it to the current date (whatever
that may be) according to that field's "delta" (i.e., +5 days from today,
-41 days from today, etc).

This way the "state" of every object in the database remains the same as it
is on any other day, because the ONLY variable that ever changes in a
database dump is its relationship to the current date (time always
changes). I need to keep that consistency to ensure that demos with
potential clients always follow the exact same "pitch" (otherwise there may
be an expired object over here, a process that may have already happened
over there, an event that is no longer in the future, etc).

I'm honestly just surprised that nobody has ever encountered a scenario
where they would need something like this before in Django. I can't be the
only one running scripted demos of a product with potential clients. Seems
like there would be a "django-demo" app for this or something. If you guys
help me figure out a good way to do this, I'll be happy to distribute it on
PyPi.

Thanks again for the help guys.

--
Joey Espinosa
Python Developer
http://about.me/joelinux
On Apr 12, 2013 8:13 PM, "Tom Evans" <tevans...@googlemail.com> wrote:

> On Fri, Apr 12, 2013 at 8:00 PM, Joey Espinosa
> <jlouis.espin...@gmail.com> wrote:
> >
> > Hey guys,
> >
> > I have a situation where I have test data that has been entered into a
> > demo database (MySQL). During the demo of the app with a customer, data
> will
> > be altered. After the demo is complete, I need to "reset" the demo data
> back
> > to what it was before the demo.
> >
> > I realize I could do this easily by dumping the database and then
> > restoring it after the demo is complete, but there's a catch... the dates
> > all need to change, too.
> >
> > So, say the demo happens on 05/01. I have an "Event" object with a date
> of
> > "05/22" (21 days in the future). When the demo gets reset (I'm planning
> on a
> > nightly reset, maybe 2am or something), it needs to change ALL the dates
> in
> > the database to have the same "timedelta" to the next day. So on the next
> > day, 05/02, that same "Event" object would have a date of "05/23" (still
> 21
> > days in the future). This is necessary to keep things like date-based
> > notifications, triggers, and other related things always in the same
> state
> > whenever the demo occurs.
> >
> > I figure the steps would go something like this:
> > 1) Dump database
> > 2) // do demo
> > 3) Restore database from dump
> > 4) Some sort of django management command run on a cronjob to change all
> > dates (or maybe straight SQL in a PROCEDURE or something).
> >
> > Any ideas on how to accomplish this?
>
> Use traditional fixtures for any objects that are not date dependant.
>
>
> https://docs.djangoproject.com/en/1.5/howto/initial-data/#providing-initial-data-with-fixtures
>
> Use SQL fixtures for any objects that are date dependant, and specify
> the date field in terms of "NOW() + INTERVAL 21 DAY" or similar.
>
>
> https://docs.djangoproject.com/en/1.5/howto/initial-data/#providing-initial-sql-data
>
> You can use the dumpdata command to create traditional fixtures, the
> SQL ones you will need to craft by hand.
>
> Cheers
>
> Tom
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-users?hl=en.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to