Wednesday, June 1, 2011

Re: save out a test database?

That's a good pointer, thanks. However I'm still confused about how I
can actually dump out the data from my test run? For example, say I
have a particular test and I want to dump the data at some certain
point. I can put in pdb.set_trace() in the code to stop at the
appropriate point, but what do I call from that point to create the
mydata.json file that then gets loaded with the command

django-admin.py testserver mydata.json

Thanks!

Margie


On May 29, 7:28 pm, Jason Culverhouse <ja...@mischievous.org> wrote:
> On May 29, 2011, at 7:13 PM, Margie Roginski <margierogin...@yahoo.com> wrote:
>
> > Anyone know if there is a way to save out a test database that is
> > created through the django TestCase module?
>
> I think this gets you close:
>
> https://docs.djangoproject.com/en/1.2/ref/django-admin/#testserver-fi...
>
> django-admin.py testserver
> Runs a Django development server (as in runserver) using data from the given fixture(s).
>
>
>
>
>
>
>
> > IE, say I have a test that runs part way through.   I'd like to save
> > it out and then modify my settings.py to refer to the saved out test
> > database and take a look at it via my web client (ie, runserver) - is
> > that possible?
>
> > Thanks for any pointers,
>
> > Margie
>
> > --
> > 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+unsubscribe@googlegroups.com.
> > For more options, visit this group athttp://groups.google.com/group/django-users?hl=en.

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

Re: Auditing Record Changes in All Admin Tables

No problem.

One final piece of advice would be to move the readonly_fields out of Entity1Admin and into AuditAdmin. That way you only have to define it once and inherit from it as with all the other options rather than re-defining it for each new model.

Ryan

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To view this discussion on the web visit https://groups.google.com/d/msg/django-users/-/RDk4VnBBdU1mck1K.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

Re: Auditing Record Changes in All Admin Tables

Bingo! Everything's working. Here's the complete solution for others:

models.py
-------------
from django.db import models
from django.contrib import admin

class AuditedTable(models.Model):
created = models.DateTimeField(auto_now_add=True)
created_by =
models.CharField(blank=True,max_length=20,editable=False)
updated = models.DateTimeField(auto_now=True)
updated_by =
models.CharField(blank=True,max_length=20,editable=False)
class Meta:
abstract = True

class Entity1(AuditedTable):
title = models.CharField(max_length=20)
...

admin.py
-----------
from myapp.models import Entity1
from django.contrib import admin
from django.db import models

class AuditAdmin(admin.ModelAdmin):
def save_model(self, request, obj, form, change):
if change:
obj.updated_by = request.user.username
else:
obj.created_by = request.user.username
obj.save()

class Entity1Admin(AuditAdmin):
list_display =
('title','created','created_by','updated','updated_by')
readonly_fields = ('created','created_by','updated','updated_by')

admin.site.register(Entity1,Entity1Admin)

------------
Thanks again for the excellent help Ryan.

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

column cannot be null

blank = True means that a django form will not require a value, but the database still does so it's expected that you provide a value elsewhere. In order to allow a null entry into the database, you will need to add null = True to that definition aswell

Hope this helps,

Ryan

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To view this discussion on the web visit https://groups.google.com/d/msg/django-users/-/WFcxX2R4ZFB1VW9K.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

Re: Auditing Record Changes in All Admin Tables

That bit is the easy bit :p

Just change request.user to request.user.username

Ryan

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To view this discussion on the web visit https://groups.google.com/d/msg/django-users/-/RXpUd1BTX2E3RVVK.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

Re: Auditing Record Changes in All Admin Tables

Found the solution to display the audit fields in the change list and
change form -- add these lines in admin.py:

class Entity1Admin(AuditAdmin):
list_display =
('title','created','created_by','updated','updated_by')
readonly_fields = ('created','created_by','updated','updated_by')

So now I just need to figure out why "obj.updated_by = request.user"
stuffs the user ID instead of the user name, and this solution will be
good to go.

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

column cannot be null

I'm getting an error leaving a field blank but I have blank = True in
the model

IntegrityError at /admin/afiliados/afiliado/add/
(1048, "Column 'titular_id' cannot be null")
Request Method: POST
Request URL: http://localhost/mysite/admin/afiliados/afiliado/add/
Django Version: 1.3
Exception Type: IntegrityError
Exception Value:
(1048, "Column 'titular_id' cannot be null")


------------------------
class afiliado(models.Model):
....other fields...
titular = models.OneToOneField("self",blank = True)


Thanks!

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