Re: Testing with a custom user model as a ForeignKey in Django 1.5

2013-03-16 Thread Felipe Coelho
2013/3/14 Felipe Coelho 

> I'm using Django 1.5 and I'm trying to make an application work with
> any custom user model.
>
> The issue is that I want to be able to test the app as well, but I
> can't find a way to make `ForeignKey` model fields to test correctly
> using custom user models. When I run the test case attached below, I
> get this error:
>
> ValueError: Cannot assign "":
> "ModelWithForeign.user" must be a "User" instance.
>
> This is the file I'm using for testing:
>
> from django.conf import settings
> from django.contrib.auth import get_user_model
> from django.contrib.auth.tests.custom_user import CustomUser,
> CustomUserManager
> from django.db import models
> from django.test import TestCase
> from django.test.utils import override_settings
>
> class NewCustomUser(CustomUser):
> objects = CustomUserManager()
> class Meta:
> app_label = 'myapp'
>
> class ModelWithForeign(models.Model):
> user = models.ForeignKey(settings.AUTH_USER_MODEL)
>
> @override_settings(
> AUTH_USER_MODEL = 'myapp.NewCustomUser'
> )
> class MyTest(TestCase):
> user_info = {
> 'email': 'al...@bob.net',
> 'date_of_birth': '2013-03-12',
> 'password': 'password1'
> }
>
> def test_failing(self):
> u = get_user_model()(**self.user_info)
> m = ModelWithForeign(user=u)
> m.save()
>
> I'm referencing the user model in the `ForeignKey` argument list as
> described in
> https://docs.djangoproject.com/en/dev/topics/auth/customizing/#django.contrib.auth.get_user_model
> ,
> but using `get_user_model` there doesn't change anything, as the
> `user` attribute is evaluated before the setting change takes place.
> Is there a way to make this ForeignKey play nice with testing when I'm
> using custom user models?
>

Since this question didn't get as much love as I expected, let me rephrase
it:

Is is possible to drop and recreate specific database tables during
testing? That would allow me to alter the model with the offending
ForeignKey, recreate the table and use it during testing. The database
content is already flushed between tests, so if I group the tests in a good
way I hope that the overhead of a drop/create table will not be as heavy as
it would be.

-- 
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.




Re: Problems install/download Django 1.5

2013-03-16 Thread breg
On Friday, March 15, 2013 12:04:56 PM UTC+1, Daniel Roseman wrote:
>
> On Friday, 15 March 2013 10:05:48 UTC, br...@kanka.de wrote:
>
>> Because the 'brand' comprises a package manager? ...
>> *aptitude install libapache2-mod-wsgi*
>>
> I found that after browsing several blogs - it should be in the Django 
>> docs.
>>
>
> That's a detail restricted to Debian-based brands of Linux. I can't 
> imagine why that should be in the Django docs. 
>

So where do you propose that the intersection between Django and Debian 
should be documented, and discussed?
 

> Same with the *WSGIScriptAlias *that needs to be inserted in apaches 
>> config.
>>  
>>
>>> Then, what is the connection to the *wsgi.*py that is generated by *
>>> startproject*?
>>>
>>
>> That has nothing to do with Debian, and *is* in the Django docs.
> https://docs.djangoproject.com/en/1.5/howto/deployment/wsgi/modwsgi/
>

Okay, I overread this, it's new in 1.4, and as I started with 1.3, at the 
time this part of mod_wsgi integration was more tedious.
 

> In other words, you haven't read the documentation you're complaining 
> about being incomplete.
>

My complaint remains about missing integration/documentation with debian.
Editing vhost.conf directly is not debian's way, which uses the *
mods/sites-enabled* mimics (which makes a lot sense btw). 
Secondly, python 2.7 being "highly recommended" for Dj 1.5 can not be used 
in debian stable. 
Installing a virtualenv again undermines package management control. 

So it'd not my personal problem as you try to put it, it's the question to 
the Django community if they want a warm insider club or a growing 
community. 

-- 
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.




How to retrieve an object from a custom template tag?

2013-03-16 Thread Andre Lopes
Hi all,

I'm trying to retrieve an object from a custom template tag. This is possible?

I explain here with details what I'm expecting to do?

http://stackoverflow.com/questions/15450003/django-how-to-retrieve-an-object-from-a-custom-template-tag

Any clues? What is the best way to avhieve this?


Best Regards,

-- 
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.




Re: Error: No module named books

2013-03-16 Thread Gaurav Munjal
Thank you Chris! I changed mysite.books to books and everything works fine 
now.

On Friday, November 30, 2012 7:54:36 AM UTC+5:30, Chris Recher wrote:
>
> Thanks for the help everyone. I was using 1.4.x, not the 1.0 the book is 
> based on. After fooling around with the commands for a bit, I was able to 
> figure out that the problem was in the INSTALLED_APPS section - I included 
> 'mysite.books', but the new way to do that is just 'books'.
>

-- 
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.




Apache Vhosting issue in Ubuntu; one vhost is serving everything

2013-03-16 Thread Elliott Brun
Been at this for a bit today, one vhost file is defaulting and  takes over 
and serves for both my URLs:


Example: ( server1 is serving for www.server2.com ??? )

www.server1.com

www.server2.com

vhost confs:

server1

ServerName www.server1.com
ErrorLog /.../apache/error.log

AliasMatch ^/([^/]*\.css) /opt/ef/static/css/$1


Allow from all


Alias /media/ /...f/media/
Alias /static/ /...f/static/


Order deny,allow
Allow from all



Order deny,allow
Allow from all




WSGIScriptAlias / /...apache/server.wsgi

server2

ServerName www.server2.com
ErrorLog /.../apache/error.log

AliasMatch ^/([^/]*\.css) /opt/ef/static/css/$1


Allow from all


Alias /media/ /...f/media/
Alias /static/ /...f/static/


Order deny,allow
Allow from all



Order deny,allow
Allow from all




WSGIScriptAlias / /...apache/server.wsgi

To get my second site to work I have to disable the alphabetically earlier 
vhost.

Am I matching incorrectly?


Realtime apache logs show the right URL, but serving the wrong files!



-- 
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.




Re: [ANN] Introducing Brillixy - Django admin skin & customization kit

2013-03-16 Thread Alexey Kinyov
Hi, Derek!
First of all, thank you! :)

> Looks good ... I think a demo with more items in it would be useful se we
> can see how page navigation works.  It also seems that there is no record
> count when you add a filter (eg. "displaying 5 of 20")?

Sure, you're right - actually with large amount of data current design
doesn't look great, so we're working on newer one :) I've placed count
filter to search block - so when no search fields provided the record
count is not visible - it's actually also a bug related to design.

> * will there be guidlines for  customising fonts, colors etc. (the buttons
> are too big & bright right compared to the text)

Custom css & js was one of priority features planned, so it's ready!
And I've updated docs on that part. You actually can build custom
Bootstrap css (http://twitter.github.com/bootstrap/customize.html) and
replace default one with it.

> * how easy is it to change template layout - e.g. I prefer filters on the
> right where they are out the way (preferable hidden by javascript,
> actually);

With current layout filters on right look not nice :) But templates
can be overridden the same way as usual Django admin templates, e.g.
by placing 'admin/change_list.html' to template paths. We're using
Bootstrap grid for layout, so you may just copy-paste template source
and swap the blocks.

Alex
///

On Thu, Mar 14, 2013 at 6:38 PM, Derek  wrote:
> On Tuesday, 12 March 2013 17:58:22 UTC+2, rudyryk wrote:
>>
>> Hello everyone!
>>
>> Today we've released alpha of Brillixy https://github.com/05bit/brillixy.
>>
>> This is a Django admin skin with some extras. Actually it's an
>> alternative to Grapelli, Admin Tools and other apps that changes
>> standard Django admin look and user experience. It's simple and
>> minimal at the moment and we're going to keep it the way like that.
>>
>> I'm working on it with Vasily Sadovnikov and Pavel Yakovlev - they
>> helped me with vision and are working on design improvevents. Thank
>> you guys!
>>
>> Core features:
>>
>> - skin powered by basic Twitter Bootstrap with responsive layout +
>> Awesome Font
>> - easy header customization: logo & title
>> - lighter nav breadcrumbs: no application index
>> - custom dashboard panels
>>
>> It seems that most of standard admin functions are working. There're
>> some issues with Django 1.4.x inlines, as I used Django 1.5 templates
>> and scrips as basis. And I see we're not perfect with design and
>> navigation, so we're working on that :)
>>
>> You're welcome to make a test-drive, and I would really appreciate any
>> feedback. Please, let me know if it does fit your real projects! :)
>>
>> Alex K. rudyryk
>> ///
>
>
> Alex
>
> Looks good ... I think a demo with more items in it would be useful se we
> can see how page navigation works.  It also seems that there is no record
> count when you add a filter (eg. "displaying 5 of 20")?
>
> Two questions:
> * will there be guidlines for  customising fonts, colors etc. (the buttons
> are too big & bright right compared to the text)
> * how easy is it to change template layout - e.g. I prefer filters on the
> right where they are out the way (preferable hidden by javascript,
> actually); also the elements seem to be scattered on the page and maybe they
> need to be "grouped" somehow (not a designer, just saying what I see...)
>
> Derek
>

-- 
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.




Django on Jython - Newbie installation difficulties

2013-03-16 Thread SeeGull
Hello,

I am trying to install Django with Jython.

System - Windows 7, 64bit
Jython - 2.5.4rc1 (installed succesfully)
Django - 1.5 (not yet installed)

When I am in the unpacked Django-1.5 directory and try to run the command
line instruction 'python setup.py install' I get the error message:

'  

I can imagine that it is something very simple that only an ABSOLUTE NEWBIE
could ever get wrong. So we all know what I am :)

Many thanks for any help in taking my first wobbly steps.



--
View this message in context: 
http://python.6.n6.nabble.com/Django-on-Jython-Newbie-installation-difficulties-tp5010361.html
Sent from the django-users mailing list archive at Nabble.com.

-- 
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.




Re: Django on Jython - Newbie installation difficulties

2013-03-16 Thread Alexey Kinyov
Hi, SeeGull!

It seems that Django 1.5 is incompatible with your version of Jython
(or with Jython at all, I don't know).

I've looked at 'django/utils/version.py' (you can see from traceback -
exception raised in this file):
https://github.com/django/django/blob/master/django/utils/version.py

So, the issue is in the line 1:
from __future__ import unicode_literals

That means Jython 2.5.4rc1 doesn't have system '__future__' module.

May I ask, why are you using Jython? :)

Alex
///

On Sat, Mar 16, 2013 at 8:11 PM, SeeGull  wrote:
> Hello,
>
> I am trying to install Django with Jython.
>
> System - Windows 7, 64bit
> Jython - 2.5.4rc1 (installed succesfully)
> Django - 1.5 (not yet installed)
>
> When I am in the unpacked Django-1.5 directory and try to run the command
> line instruction 'python setup.py install' I get the error message:
>
> ' 
>
> I can imagine that it is something very simple that only an ABSOLUTE NEWBIE
> could ever get wrong. So we all know what I am :)
>
> Many thanks for any help in taking my first wobbly steps.
>
>
>
> --
> View this message in context: 
> http://python.6.n6.nabble.com/Django-on-Jython-Newbie-installation-difficulties-tp5010361.html
> Sent from the django-users mailing list archive at Nabble.com.
>
> --
> 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.




Re: plugin for selecting files

2013-03-16 Thread Larry Martell
On Fri, Mar 15, 2013 at 6:43 PM, Larry Martell  wrote:
> On Thu, Mar 14, 2013 at 5:08 PM, Shawn Milochik  wrote:
>> On Thu, Mar 14, 2013 at 6:03 PM, Larry Martell  
>> wrote:
>>>
>>> I have been googing this for 2 days and trying lots of different
>>> things, without success. I really appreciate your help - I've made
>>> more progress in the last hour when in the previous 48.
>>
>>
>> Glad I could help, but you really should search the Django docs and
>> Google first. This is definitely one you would have found in the
>> Django docs.
>>
>> https://docs.djangoproject.com/en/1.5/topics/http/file-uploads/
>
> Thanks. Using the examples at
> http://stackoverflow.com/questions/5871730/need-a-minimal-django-file-upload-example
> and the above I was able to get this working.

Is there a way for me to get the path on the local computer of the
files? In request.FILES all I see are the base names.

-- 
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.




Re: Problems install/download Django 1.5

2013-03-16 Thread Shawn Milochik
On Sat, Mar 16, 2013 at 9:25 AM,   wrote:



> Secondly, python 2.7 being "highly recommended" for Dj 1.5 can not be used
> in debian stable.
> Installing a virtualenv again undermines package management control.



Using virtualenv does not undermine package management and is the
best-practice and most-recommended way to handle it. In fact, it
significantly *helps* your package management system by not polluting
your OS's default Python libraries with all the stuff you install for
a single project.

Plus, you are eventually going to want to work on more than more than
one project, or multiple versions of your app, for example as you
prepare to migrate your app to newer versions of Django as it
continues to evolve.

-- 
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.




Re: Django on Jython - Newbie installation difficulties

2013-03-16 Thread SeeGull
Thanks for the response.

1. I have now isolated the problem with the install. It is indeed a version
compatibility mismatch. Django 1.5* does not support Jython 2.5*. 

Django 1.5* requires the unstable development version Jython 2.7*
Django 1.4* is compatible with the stable old version Jython 2.5*

I have now chosen the Django 1.4* route. I can up-version later as soon as a
stable Jython 2.7* is released.

2. Why Jython at all? I am experimenting. I have a web site concept that
points strongly in the direction of a Python based solution. However, the
ability to easily extend the functionality with Java code embedding and JVM
execution is quite interesting too. I am a lazy programmer and want to
maximise the leverage I can get with my minimal code.

Would you suggest a different approach?



--
View this message in context: 
http://python.6.n6.nabble.com/Django-on-Jython-Newbie-installation-difficulties-tp5010361p5010374.html
Sent from the django-users mailing list archive at Nabble.com.

-- 
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.




Re: plugin for selecting files

2013-03-16 Thread Sanjay Bhangar
On Sun, Mar 17, 2013 at 12:00 AM, Larry Martell  wrote:
>
> Is there a way for me to get the path on the local computer of the
> files? In request.FILES all I see are the base names.
>

No. That would be pose serious security / privacy issues and afaik, is
definitely not possible to do. What would be your use-case for getting
the path on the user's machine?

-Sanjay

-- 
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.




Re: plugin for selecting files

2013-03-16 Thread Larry Martell
On Sat, Mar 16, 2013 at 2:47 PM, Sanjay Bhangar  wrote:
> On Sun, Mar 17, 2013 at 12:00 AM, Larry Martell  
> wrote:
>>
>> Is there a way for me to get the path on the local computer of the
>> files? In request.FILES all I see are the base names.
>>
>
> No. That would be pose serious security / privacy issues and afaik, is
> definitely not possible to do. What would be your use-case for getting
> the path on the user's machine?

It was a request by my client to display the paths on the page after
the files are downloaded.

-- 
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.




Re: django templates and tex/latex

2013-03-16 Thread thanos
On Thu, Mar 14, 2013 at 9:58 AM, Bill Freeman  wrote:

> Note that you don't have to use the Django template engine to render
> things.
>
> For one thing, if you found a less problematic templating engine, using it
> as
> well doesn't prevent you from using Django's template engine for other
> pages.
>
> You could also roll your own by coming up with, for example, a TeX friendly
> syntax for variable substitution (by which I mean, doesn't collide with
> syntax
> that you will be using - best would be coming up with something that is
> actually illegal in TeX), and process things with a big regex or had coded
> parser..  You could parse this directly into the output, or this could be a
> loading stage that converts the file to a Django template (or engine of
> your
> choice) file, where the TeX/LaTeX stuff that looks like template specials
> is
> converted to a quoted structure that renders as the original.
>
> A final approach would be to use TeX definitions to perform your variable
> substitutions, prepending a stanza that makes the definitions at render
> time.  (Though making this work where you want template loops is much
> harder.)
>
>
> On Wed, Mar 13, 2013 at 2:15 PM, Ken  wrote:
>
>> Actually, that's exactly what I'm trying to do.  I have database tables
>> whose
>> columns contain TeX fragments.  I am trying to generate various file
>> outputs
>> from database searches - TeX, pdf, etc.
>>
>> I could construct the tex file on the fly with python strings as you
>> suggest but
>> that's rather cumbersome.  It's simpler with a template.
>>
>> I've also considered using the xml.element api to construct my own
>> template
>> but that would set me back several weeks.  I'm trying to finish. :/
>>
>> I have something that almost resembles a template.  It is not the most
>> flexible
>> or elegant but it works.  I have a single replacement string between
>> \begin{document} and \end{document} and I simply replace this one token
>> with a
>> string.replace()
>>
>>
>>
>>
>> On Wednesday, March 13, 2013 11:39:18 AM UTC-5, Drew Ferguson wrote:
>>
>>> On Wed, 13 Mar 2013 07:01:45 -0700 (PDT)
>>> Ken  wrote:
>>>
>>> > I would like to write a tex/latex file with django tags in it.  Load
>>> it
>>> > with the template loader and render it with a context.  The problem is
>>> > that my tex/latex file has quite a few '{%' in them.   They are
>>> > conventional in TeX for writing readable macros and are used to escape
>>> > the newline.  I could try rewriting them but before I do, I thought
>>> I'd
>>> > ask if this is even worth tackling.  TeX uses curly braces as grouping
>>> > and percent signs as a comment.
>>> >
>>> > The TeX file would look rather confusing but the more important
>>> question
>>> > is what the loader does when it sees braces and brace comments.  Is it
>>> > possible to reassign the block and variable tags?
>>> >
>>> > Thanks
>>> >
>>> >
>>>
>>> I have done this in the past (with Plone rather than django) by calling
>>> a
>>> python wrapper script to generate a file which latex can process;
>>> essentially construct the Latex source as python strings
>>> and have the script assemble the components you want. The objective was
>>> to
>>> generate a PDF file by Latex with variables fed from SQL & a web page.
>>> But
>>> this may not be what you are interested in.
>>>
>>> Are you trying to render a Latex source document as a web page?
>>>
>>> --
>>> Drew
>>>
>>  --
>> 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.
>
>
>


I use the mako template  engine + TeX to generate all my pdf pages from a
django app. It's works just fine.  Years ago for NYSE I wrote my own
template engine that used just TeX markup, but it was just like so many
other projects it *dried up and died*.

thanos

-- 
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

Re: Testing with a custom user model as a ForeignKey in Django 1.5

2013-03-16 Thread Russell Keith-Magee
On Sat, Mar 16, 2013 at 9:14 PM, Felipe Coelho  wrote:

> 2013/3/14 Felipe Coelho 
>
>> I'm using Django 1.5 and I'm trying to make an application work with
>> any custom user model.
>>
>> The issue is that I want to be able to test the app as well, but I
>> can't find a way to make `ForeignKey` model fields to test correctly
>> using custom user models. When I run the test case attached below, I
>> get this error:
>>
>> ValueError: Cannot assign "":
>> "ModelWithForeign.user" must be a "User" instance.
>>
>> This is the file I'm using for testing:
>>
>> from django.conf import settings
>> from django.contrib.auth import get_user_model
>> from django.contrib.auth.tests.custom_user import CustomUser,
>> CustomUserManager
>> from django.db import models
>> from django.test import TestCase
>> from django.test.utils import override_settings
>>
>> class NewCustomUser(CustomUser):
>> objects = CustomUserManager()
>> class Meta:
>> app_label = 'myapp'
>>
>> class ModelWithForeign(models.Model):
>> user = models.ForeignKey(settings.AUTH_USER_MODEL)
>>
>> @override_settings(
>> AUTH_USER_MODEL = 'myapp.NewCustomUser'
>> )
>> class MyTest(TestCase):
>> user_info = {
>> 'email': 'al...@bob.net',
>> 'date_of_birth': '2013-03-12',
>> 'password': 'password1'
>> }
>>
>> def test_failing(self):
>> u = get_user_model()(**self.user_info)
>> m = ModelWithForeign(user=u)
>> m.save()
>>
>> I'm referencing the user model in the `ForeignKey` argument list as
>> described in
>> https://docs.djangoproject.com/en/dev/topics/auth/customizing/#django.contrib.auth.get_user_model
>> ,
>> but using `get_user_model` there doesn't change anything, as the
>> `user` attribute is evaluated before the setting change takes place.
>> Is there a way to make this ForeignKey play nice with testing when I'm
>> using custom user models?
>>
>
> Since this question didn't get as much love as I expected, let me rephrase
> it:
>
> Is is possible to drop and recreate specific database tables during
> testing? That would allow me to alter the model with the offending
> ForeignKey, recreate the table and use it during testing. The database
> content is already flushed between tests, so if I group the tests in a good
> way I hope that the overhead of a drop/create table will not be as heavy as
> it would be.
>

Essentially, no -- at least, not out of the box. You might be able to rig
together some setUp() and tearDown() calls that invoke the table creation
code that Django executes as part of syncdb, but I can't point you at a
simple example of working code or anything like that.

Internally, Django has avoided this sort of problem in three ways:

 1) Using tests that need the models, but don't actually touch the
database. This means you can put the model definition inline in the test
code, so AUTH_USER_MODEL has the right value when the code is run. This
lets us test validation conditions, etc, but not hit the database. You
*might* be able to get away with manually running syncdb in the middle of
the test -- Django's swappable_model test contains an example of doing
this, but only for the purposes of recreating permissions, not tables.

 2) Define 2 "ModelWIthForeign" classes, and use the "right" one depending
on what the User model is at the time of test. This works fine for Django's
purposes because "ModelWithForeign" is a test-only model, so it doesn't
matter if you have a few of them. This approach won't be successful if
you're actually shipping ModelWithForeign as a core part of your system.

 3) Use test decorators to skip the test if a non-default user model is in
use.

Any suggestions on how to improve Django's testing infrastructure to handle
custom User models would be gratefully accepted (especially if they come
with patches). It's still new code, so reports of problems like yours are
helpful in shaping what features we've missed during initial development.

Yours,
Russ Magee %-)

-- 
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.




Re: My Data dont be updated with my forms

2013-03-16 Thread Dan Gentry
Rafael,

This is a bit of a wild guess, but I'm wondering if your form isn't 
validating.  Since your template doesn't seem to be displaying any errors, 
you wouldn't know it.  

Also, since the Url column is marked as unique, but you are excluding it 
from the form, it may be the field throwing the error.

Just to check, add {{form.errors}} to your template and give it a try.

Best of luck,

Dan



-- 
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.