Re: How can I create models which only required during tests in Django 1.7c1?

2014-08-29 Thread Yo-Yo Ma
I use mock for every testcase I have in my app (no queries in my entire 
test suite), but sometimes I also need to include a real model (but no 
queries or db), due to the complexity of the situation (e.g., relying on a 
bit more of Django's inner workings without having to mock 10-15 methods). 
In other words, despite unit tests being very controlled and specific to a 
few lines of code, sometimes I need to allow some infrastructure to run, in 
order to keep my tests simple, and more importantly, to keep them forward 
compatible.

To reiterate, I'm aware that, in a perfect world, the required components 
would just be mocked, but for my 9 test methods, I would have more than 
doubled the length of the tests and been left with an unreadable mess.

Here's the solution I came up with last night, after asking the question: 
https://gist.github.com/anonymous/a11898d0cd8ffc78b531 
(get_model(, ) was messier, due to the need for exception 
handling).

On Friday, August 29, 2014 10:57:05 AM UTC-4, Alex Chiaranda wrote:
>
> Hi, can't you guys mock these models ?
>
> On Thursday, August 28, 2014 9:31:04 PM UTC-3, Yo-Yo Ma wrote:
>>
>> Ugh... same problem here. It seems you can't really create a model in 
>> setUp anymore. I'll post a reply, if I find anything.
>>
>> On Wednesday, July 16, 2014 10:17:56 AM UTC-4, Alisue Lambda wrote:
>>>
>>> Hi all. 
>>>
>>> Well today I tried Django 1.7c1 with my program and found that the 
>>> previous testing strategy seems not work.
>>>
>>> I have several models which only required during tests. Before Django 
>>> 1.7, I could create these kind of temporary models by defining these in 
>>> `app/tests/models.py` with `app_label` specification like this (
>>> https://github.com/lambdalisue/django-permission/blob/master/src/permission/tests/models.py).
>>>  
>>> It was quite good strategy for me because I could reduce the dependency of 
>>> the apps and make the app independent.
>>>
>>> But now, it seems Django 1.7c1 cannot find this kind of definitions. I 
>>> have to add `app.tests` in `INSTALLED_APPS` which was not required before 
>>> Django 1.7c1.
>>> However, if I add `app.tests` and `app2.tests`, I have to modify `label` 
>>> of the `app2.tests` because there is already `app_label='tests'` in the 
>>> registry. It is quite tough job while I have a lot of apps which follow 
>>> this strategy to test the app.
>>> Additionally, I don't really want to list `app.tests` in my 
>>> `INSTALLED_APPS` while it is not actually app which required for the site.
>>>
>>> So I wonder if there are any better way to define the temporary models. 
>>> In summary, what I want to do is
>>>
>>> 1. I want to add temporary models which only required during tests
>>> 2. I don't want to mess the db with temporary models (except during 
>>> tests)
>>>
>>> Any idea? Thank you for your cooperation.
>>>
>>>
>>> Best regard,
>>>
>>>

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/5cad5371-3a23-4f53-bc84-41a809976f04%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: How can I create models which only required during tests in Django 1.7c1?

2014-08-28 Thread Yo-Yo Ma
Ugh... same problem here. It seems you can't really create a model in setUp 
anymore. I'll post a reply, if I find anything.

On Wednesday, July 16, 2014 10:17:56 AM UTC-4, Alisue Lambda wrote:
>
> Hi all. 
>
> Well today I tried Django 1.7c1 with my program and found that the 
> previous testing strategy seems not work.
>
> I have several models which only required during tests. Before Django 1.7, 
> I could create these kind of temporary models by defining these in 
> `app/tests/models.py` with `app_label` specification like this (
> https://github.com/lambdalisue/django-permission/blob/master/src/permission/tests/models.py).
>  
> It was quite good strategy for me because I could reduce the dependency of 
> the apps and make the app independent.
>
> But now, it seems Django 1.7c1 cannot find this kind of definitions. I 
> have to add `app.tests` in `INSTALLED_APPS` which was not required before 
> Django 1.7c1.
> However, if I add `app.tests` and `app2.tests`, I have to modify `label` 
> of the `app2.tests` because there is already `app_label='tests'` in the 
> registry. It is quite tough job while I have a lot of apps which follow 
> this strategy to test the app.
> Additionally, I don't really want to list `app.tests` in my 
> `INSTALLED_APPS` while it is not actually app which required for the site.
>
> So I wonder if there are any better way to define the temporary models. In 
> summary, what I want to do is
>
> 1. I want to add temporary models which only required during tests
> 2. I don't want to mess the db with temporary models (except during tests)
>
> Any idea? Thank you for your cooperation.
>
>
> Best regard,
>
>

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/2a208687-4cf9-461f-9347-3a7efbfa066c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Pattern for Ajax Forms using Django ModelForm and Class Based Views.

2013-02-09 Thread Yo-Yo Ma
I might be worth checking out some sort of API library, like 
https://github.com/orokusaki/django-jsonrpc-2-0, which will allow you to 
perform whatever business logic you need to, and then simply return 
something like {"success": True, "errors": errors_list} - your templates 
and ordinary views could be leaner, if you A) separate your AJAX 
functionality from your non-AJAX views, and B) create a central client-side 
template (e.g., https://github.com/janl/mustache.js/) for rendering the 
contents of your model.

On Friday, February 8, 2013 7:38:18 PM UTC-5, Kelly Nicholes wrote:
>
> What's the best practice for this?  In my function based views, I'd check 
> if the form is_ajax() and if so, validate the form, render_to_string it to 
> a form template, and return that in a json dump along with a status code. 
>  Then I check the status code to see if there are errors.  If so, I close 
> the modal that the form is in, notify the user of successful addition, and 
> move on.  If there are errors, I replace the form's HTML in the modal with 
> the new HTML that contains the form with error messages.  This sucks 
> because I have to do this for every form and for every view that I have.  

-- 
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: Does ``QuerySet.select_for_update`` lock related (joined) rows as well?

2012-09-05 Thread Yo-Yo Ma
Thanks, Tom. That does help.

On Wednesday, September 5, 2012 6:02:27 AM UTC-4, Tom Evans wrote:
>
> On Wed, Sep 5, 2012 at 1:45 AM, Yo-Yo Ma > 
> wrote: 
> > restaurant = 
> > 
> Restaurant.objects.select_for_update().select_related('owner').get(name=u'Koala
>  
>
> > Kafe') 
> > 
> > Assuming the ``owner`` field points to a ``Person`` table, will the 
> > aforementioned query prevent the ``Person`` row returned for the Koala 
> > Kafe's owner from being saved in a separate transaction? 
> > 
> > (I will be using Postgres and using ``transaction.commit_on_success``) 
> > 
>
> select_for_update() … 
>
> "Returns a queryset that will lock rows until the end of the 
> transaction, generating a SELECT ... FOR UPDATE SQL statement on 
> supported databases." 
>
> Postgresql handles this … 
>
> "If specific tables are named in FOR UPDATE or FOR SHARE, then only 
> rows coming from those tables are locked; any other tables used in the 
> SELECT are simply read as usual. A FOR UPDATE or FOR SHARE clause 
> without a table list affects all tables used in the statement. If FOR 
> UPDATE or FOR SHARE is applied to a view or sub-query, it affects all 
> tables used in the view or sub-query." 
>
>
> http://www.postgresql.org/docs/9.0/static/sql-select.html#SQL-FOR-UPDATE-SHARE
>  
>
> Django doesn't specify any tables when it generates a SELECT … FOR UPDATE 
> query: 
>
>
> https://github.com/django/django/blob/master/django/db/backends/__init__.py#L585
>  
>
> Hope that helps 
>
> Tom 
>

-- 
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/-/EaUInBi9N0MJ.
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 at 
http://groups.google.com/group/django-users?hl=en.



Does ``QuerySet.select_for_update`` lock related (joined) rows as well?

2012-09-04 Thread Yo-Yo Ma
restaurant = 
Restaurant.objects.select_for_update().select_related('owner').get(name=u'Koala 
Kafe')

Assuming the ``owner`` field points to a ``Person`` table, will the 
aforementioned query prevent the ``Person`` row returned for the Koala 
Kafe's owner from being saved in a separate transaction?

(I will be using Postgres and using ``transaction.commit_on_success``)

-- 
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/-/dTAAVvZVDaAJ.
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 at 
http://groups.google.com/group/django-users?hl=en.



What happens when you use ``select_for_update`` with ``select_related``?

2012-08-19 Thread Yo-Yo Ma
Given a model ``Employee`` with a foreign key ``company`` pointing to a 
model called ``Company``, would the following example lock both the 
``Employee`` and ``Company`` rows that were selected?

employee = 
Employee.objects.select_for_update().select_related('company').get(pk=1)

Or, would only the ``Employee`` row be locked?

-- 
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/-/Ps3gJ6JiSnMJ.
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 at 
http://groups.google.com/group/django-users?hl=en.



AutoField field that increments with regards to a foreign key?

2010-10-21 Thread Yo-Yo Ma
Example:

Company has many Tickets
Tickets have a PK, as well as a "number".
Each Ticket's "number" should be the highest prior "number" for a
Ticket with the same Company

Ticket: pk: 1, number: 1, company: XYZ
Ticket: pk: 2, number: 1, company: Acme
Ticket: pk: 1, number: 2, company: XYZ

unique_together=(("number", "company"),)  # number is not unique
itself.

How should I handle this non-sense?


Confusing, convoluted, in-depth (sort of) explanation:

I have a model that sets the value of one of it's fields in the save()
method. It does this by reading the value of another field, and using
that value to calculate the value based on how many instances there
are with the same value in the other field (Basically an auto field
that increments with regards to a foreign key). The field that save()
sets is a unique field. This means that if 2 people on other sides of
the globe hit "submit" at the same time, the number of instances with
"other field"s value will be the same (e.g. 500). Then save() will
make self.number = 501, causing an IntegrityError for which ever one
takes longer to finish. How can I get around this? Or, better yet: How
should I do this instead?


Thanks in advance.

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



Re: Something breaking if tag

2010-09-29 Thread Yo-Yo Ma
request.GET.get('subtopic') is returning a string, so your if
statement is roughly equivalent to:

>>> 1 == '1'
False

The sub_topic = int(request.GET.get('subtopic')) is the correct way to
do that. At first glance it seems like a lot of work, but if Django
tried to deserialize URL params automatically into Python objects
(like int), you would have all sorts of issues (like a "username"
being passed in as an int because a user decides to make their name
"1234", and so on).



On Sep 29, 12:52 pm, aa56280  wrote:
> I have in my template the following:
>
> {% if subtopic.id == selected_id %}...{% endif %}
>
> subtopic.id is being pulled from a list of subtopics that I'm looping
> over.
>
> selected_id is being sent to the template by the view after some form
> processing:
> #views.py
> selected_id = request.GET.get('subtopic', '')
> ...
>
> For some reason, my {% if %} statement in the template isn't getting
> evaluated even when the values of both subtopic.id and selected_id are
> the same. It does, however, work properly if I do the following before
> I send selected_id to the template:
> #views.py
> selected_id = int(selected_id)
>
> Why is this? I'm wondering.
>
> Thanks in advance for any insight.

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



Re: What is the correct way to copy an object from one model to a similar model?

2010-09-29 Thread Yo-Yo Ma
Thanks guys. I appreciate the help.

On Sep 29, 6:43 am, bruno desthuilliers
 wrote:
> On 29 sep, 12:31, Steve Holden  wrote:
>
> > On 9/29/2010 5:25 AM, Daniel Roseman wrote:
> > > You can use the get_all_field_names method in model._meta to get all
> > > the actual fields, and set them on the duplicate:
>
> > >     for field in foo._meta.get_all_field_names():
> > >         setattr(spam, getattr(foo, field))
>
> > I believe that last line should read
>
> >         setattr(spam, field, getattr(foo, field))
>
> Indeed. Note that you may not want to copy foo.pk (or at least not
> under the same name) if there's more than one Spam created for each
> Foo !-)
>
> 
> If your system actually creates a new Spam instance each time the
> "certain action" is performed against Foo, you could as well create
> the whole attributes dict and pass it to Spam.objects.create, ie:
>
> attribs = dict((fielname, getattr(foo, fieldname))
>    for fieldname in foo._meta.get_all_field_names()
>    if fieldname is not 'id' # or whatever the pk name is
>    )
>
> attribs.update(
>   foo=foo,
>   additional_attrib1='dead parrot',
>   additional_attrib2='Norwegian Blue'
>   )
>
> spam = Spam.objects.create(**attribs)
>
> HTH

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



Re: Import Error

2010-09-28 Thread Yo-Yo Ma
User logs into your site (SaadsDjangoSite.com). User goes to
CriminalCSRFSite.com while logged into yours. They put a script tag in
their page that has a post-back to 
ttp://saadsdjangosite.com/delete-everything-and-kill-kittens/.
This causes the user's logged in browser to make a request to your
site, and delete everything and kill kittens, all without the user
knowing what happened.

Follow those instructions. Make sure you put {% csrf_token %} right
after your open  tag.



On Sep 28, 11:38 pm, Saad Sharif  wrote:
> Thanks a lo :)
>
> but there is a new error
>
> The Error:
>
> Forbidden (403)
>
> CSRF verification failed. Request aborted.
>  Help
>
> Reason given for failure:
>
>     CSRF token missing or incorrect.
>
> In general, this can occur when there is a genuine Cross Site Request
> Forgery, or when Django's CSRF
> mechanism<http://docs.djangoproject.com/en/dev/ref/contrib/csrf/#ref-contrib-csrf>has
> not been used correctly. For POST forms, you need to ensure:
>
>    - The view function uses
> RequestContext<http://docs.djangoproject.com/en/dev/ref/templates/api/#subclassing-c...>for
> the template, instead of
>    Context.
>    - In the template, there is a {% csrf_token %} template tag inside each
>    POST form that targets an internal URL.
>    - If you are not using CsrfViewMiddleware, then you must use
> csrf_protecton any views that use the
>    csrf_token template tag, as well as those that accept the POST data.
>
> You're seeing the help section of this page because you have DEBUG = True in
> your Django settings file. Change that to False, and only the initial error
> message will be displayed.
>
> You can customize this page using the CSRF_FAILURE_VIEW setting.
>
> On Wed, Sep 29, 2010 at 10:39 AM, Yo-Yo Ma  wrote:
> > (r'^login/', include('macrohms.views.login')),  is incorrect.
>
> > the include() function, pertaining to urls.py is for including other
> > URL confs (so you can have sub-sections of your site contain their own
> > urls.py). You'll want to replace that line with:
>
> > url(r'^login/$', 'macrohms.views.login')),
>
> > Note, I changed two additional things - I changed your tuple to a
> > url() function call instead, and I added a $ at the end of the URL
> > pattern (denotes the end of a string in regex). The url() function is
> > the "cool" way to define URLs.
>
> > On Sep 28, 10:41 pm, Saad Sharif  wrote:
> > > Hi all,
>
> > > I created a simple login form
>
> > > My code:
> > >  > > dojoType="dijit.form.Form" >{% csrf_token %}
> > > username 
> > > password 
> > >  login 
> > > 
>
> > >  In views.py i added
>
> > > def login(request):
> > >     return render_to_response('login.html')
>
> > > In urls.py i added
>
> > > (r'^login/', include('macrohms.views.login')),
>
> > > The Error when i press login button:
> > > ImportError at /login/
>
> > > No module named login
>
> > >  Request Method: POST  Request URL:http://localhost:8000/login/Django
> > > Version: 1.2.3  Exception Type: ImportError  Exception Value:
>
> > > No module named login
>
> > >  Exception Location:
>
> > /home/saad/www/lib/python2.6/site-packages/Django-1.2.3-py2.6.egg/django/utils/importlib.py
> > > in import_module, line 35  Python Executable: /home/saad/www/bin/python
> >  Python
> > > Version: 2.6.5  Python Path: ['/home/saad/www/webapps/macrohms',
> > > '/home/saad/www/lib/python2.6/site-packages/setuptools-0.6c11-py2.6.egg',
> > > '/home/saad/www/lib/python2.6/site-packages/pip-0.8.1-py2.6.egg',
> > > '/home/saad/www/lib/python2.6/site-packages/Django-1.2.3-py2.6.egg',
> > > '/home/saad/www/lib/python2.6/site-packages/Coffin-0.3.3-py2.6.egg',
> > > '/home/saad/www/lib/python2.6/site-packages/Jinja2-2.5.2-py2.6.egg',
> > > '/home/saad/www/lib/python2.6/site-packages/WTForms-0.6.1-py2.6.egg',
> > > '/home/saad/www/lib/python2.6',
> > '/home/saad/www/lib/python2.6/plat-linux2',
> > > '/home/saad/www/lib/python2.6/lib-tk',
> > > '/home/saad/www/lib/python2.6/lib-old',
> > > '/home/saad/www/lib/python2.6/lib-dynload', '/usr/lib/python2.6',
> > > '/usr/lib/python2.6/plat-linux2', '/usr/lib/python2.6/lib-tk',
> > > '/home/saad/www/lib/python2.6/site-packages']  Server time: Tue, 28 Sep
> > 2010
> > > 23:40:56 -0500
>
> > --
> > You received this message because you are subscribed to the Google Groups
> > "Django users" group.
> > To post to this group, send email to django-us...@googlegroups.com.
> > To unsubscribe from this group, send email to
> > django-users+unsubscr...@googlegroups.com
> > .
> > For more options, visit this group at
> >http://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-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Import Error

2010-09-28 Thread Yo-Yo Ma
(r'^login/', include('macrohms.views.login')),  is incorrect.

the include() function, pertaining to urls.py is for including other
URL confs (so you can have sub-sections of your site contain their own
urls.py). You'll want to replace that line with:

url(r'^login/$', 'macrohms.views.login')),

Note, I changed two additional things - I changed your tuple to a
url() function call instead, and I added a $ at the end of the URL
pattern (denotes the end of a string in regex). The url() function is
the "cool" way to define URLs.

On Sep 28, 10:41 pm, Saad Sharif  wrote:
> Hi all,
>
> I created a simple login form
>
> My code:
>  dojoType="dijit.form.Form" >{% csrf_token %}
> username 
> password 
>  login 
> 
>
>  In views.py i added
>
> def login(request):
>     return render_to_response('login.html')
>
> In urls.py i added
>
> (r'^login/', include('macrohms.views.login')),
>
> The Error when i press login button:
> ImportError at /login/
>
> No module named login
>
>  Request Method: POST  Request URL:http://localhost:8000/login/ Django
> Version: 1.2.3  Exception Type: ImportError  Exception Value:
>
> No module named login
>
>  Exception Location:
> /home/saad/www/lib/python2.6/site-packages/Django-1.2.3-py2.6.egg/django/utils/importlib.py
> in import_module, line 35  Python Executable: /home/saad/www/bin/python  
> Python
> Version: 2.6.5  Python Path: ['/home/saad/www/webapps/macrohms',
> '/home/saad/www/lib/python2.6/site-packages/setuptools-0.6c11-py2.6.egg',
> '/home/saad/www/lib/python2.6/site-packages/pip-0.8.1-py2.6.egg',
> '/home/saad/www/lib/python2.6/site-packages/Django-1.2.3-py2.6.egg',
> '/home/saad/www/lib/python2.6/site-packages/Coffin-0.3.3-py2.6.egg',
> '/home/saad/www/lib/python2.6/site-packages/Jinja2-2.5.2-py2.6.egg',
> '/home/saad/www/lib/python2.6/site-packages/WTForms-0.6.1-py2.6.egg',
> '/home/saad/www/lib/python2.6', '/home/saad/www/lib/python2.6/plat-linux2',
> '/home/saad/www/lib/python2.6/lib-tk',
> '/home/saad/www/lib/python2.6/lib-old',
> '/home/saad/www/lib/python2.6/lib-dynload', '/usr/lib/python2.6',
> '/usr/lib/python2.6/plat-linux2', '/usr/lib/python2.6/lib-tk',
> '/home/saad/www/lib/python2.6/site-packages']  Server time: Tue, 28 Sep 2010
> 23:40:56 -0500

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



What is the correct way to copy an object from one model to a similar model?

2010-09-28 Thread Yo-Yo Ma
I have two models that are identical in structure except one has 2
extra fields. The second one is used for record keeping and is never
edited by users. The system takes the first model and copies it to the
second model, adding some extra meta information, all when a certain
action is performed against the first model.

What is the best practice for this?

spam.attribute_one = foo.attribute_one
spam.attribute_two = foo.attribute_two

Or, is there a pattern that works well?

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



Re: How do you set choices in your application?

2010-09-24 Thread Yo-Yo Ma
Anyone have any thoughts.

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



How do you set choices in your application?

2010-09-24 Thread Yo-Yo Ma
Let's say I have a model with a field called "status". I could set the
choices in three ways:

1)   status_choices = ((1, 'Completed'), (2, 'Unfinished'), (3,
'Cancelled'))


2)  status_choices = (('COM', 'Completed'), ('UNF', 'Unfinished'),
('CAN', 'Cancelled'))


Or, 3 ):

db_choices = Choice.objects.all()
status_choices = [[choice.pk, choice.description] for choice in
db_choices]

Is there any best practice? Note: Client's won't be able to define
these choices. They'll all be defined by me (or else DB would be the
answer of course).

My thoughts:

1) Risky (data is useless without python file), 2) Slower, and risky
because it might be difficult to change later, 3) a lot of work, and
slow (because of DB).

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



Re: Why Django Apps Suck

2010-09-23 Thread Yo-Yo Ma
Hey Russell,

Do you think a round table discussion in a real person context with
whiteboards and the best of the bunch (ie, at Django con or similar
event) would be a good time/place to re architecture of the
abstraction layers, perhaps to address some of the concerns brought up
in the slide show by Eric? By abstraction layers I don't just refer to
the "app" (which I don't see to be a problem as much as others do,
although I don't like how so many apps have models in them). I'm also
referring to things like; putting global functionality into urls.py,
tight coupling of built-in apps, etc.


Michael

On Sep 23, 5:40 am, Russell Keith-Magee 
wrote:
> On Thu, Sep 23, 2010 at 5:55 PM, Klaas van Schelven
>
>  wrote:
> > On Sep 23, 2:01 am, Russell Keith-Magee 
> > wrote:
>
> > So, we run into a few problems:
> > * How do we extend the models from the original extendible
> > application?
> > For this to work, we need to provide hooks in the application for
> > extendiblity. In the case of models, such a hook would be twofold:
> > 1. an abstract model to extend to provide a baseline (a default with
> > the minimum amount of fields)
> > 2. something overridable that is referred to by the rest of our app,
> > providing the concrete instance of [1] in the plain vanilla app, and
> > the concrete instance plus extensions in our extended app. (the actual
> > hook)
>
> Sure. Abstract models form the first part of this; the 'reference to
> the concrete instance' is a known problem -- the most obvious example
> of this surfacing is defining a custom User class to use in
> contrib.auth. Alex provides one possible solution (join models) in his
> talk; another (LazyForeignKey) was raised by Eric Florenzano in his
> keynote [1]. However, this is still very much an open area of debate.
> Any suggestions are welcome.
>
> [1]http://djangocon.blip.tv/file/4112452/
>
>
>
> > * how do we refer to ourselves from the various parts of the
> > extendible application?
> > Self-referral with overrides is a solved problem in the object
> > oriented world ("inheritance"). However, it's impossible in Django's
> > standard way of organizing apps, because we all use modules (not
> > classes or instances) for the various parts of the app ("models.py",
> > "views.py" etc).
> > It is not possible to pass context into a module (other than monkey
> > patching it)
>
> > Every views.py begins with a bunch of imports from the associated
> > models.py, tying the views into those particular app's models. My
> > alternative would be like so:
>
> > class View(...):
> >  def page_detail(self, request, pk=None):
> >    page = self.models.Page.objects.get(pk=pk)
> >    return render_to_response( page ...)
>
> > For models:
>
> > class Models(...):
> >  def get_Page(self):
> >    class Page(models.Model):
> >       #abstract
> >       category = models.ForeignKey(self.models.Category)
> >    return Page
> >  Page = property(get_Page)
>
> > (The above is a bit less elegant than the views example because models
> > are classes and the following therefor does not work:)
>
> > class Models(...)
> >  class Page(self, model.Model):
> >     ...
> >     category = models.ForeignKey(self.models.Category)
>
> > If anyone has an example of how to do this without a property I'd be
> > much obliged.
>
> Sure. There's at least two approaches. The first -- a method based
> approach -- is used by contrib.auth (amongst others):
>
> def my_view(request, arg1, arg2, klass=Page):
>     objects = klass.objects.filter(arg1=arg1, arg2=arg2)
>     ...
>
> The second is the class based approach, used by contrib.admin (and
> others), which is to define a class-based view, and provide methods
> like get_objects() that you can subclass to perform whatever behaviour
> you need.
>
> > Views.py methods generally have two types of parameters:
> > 1. Those that are passed in via urls.py from the request path. Love
> > 'em, couldn't live without 'em. This is what you're talking about.
> > 2. Those we add (with usefull defaults) to make our app "reusable".
> > What I was saying, is that I consider these in particular as unusable
> > in the general sense. If I subclass the idea of address in an address
> > book app (to add some field), would it make sense to refer to the
> > subclassed address class in every call to every single view function?
> > I'd say no. I'd rather say "give me my views where each view
> > understands that it should use the improved address class).
>
> Sure. And that's why you use class-based views. That's why Django's
> admin is a class.
>
> That's also why Django is in the process of getting a class-based view
> framework - again, from DjangoCon, see Ben Firshman's talk [2]
>
> [2]http://blip.tv/file/4109272
>
> Yours,
> Russ Magee %-)

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsu

Re: Problem with ForeignKey()

2010-09-22 Thread Yo-Yo Ma
Any thoughts on this?

On Sep 22, 10:47 am, Yo-Yo Ma  wrote:
> Anyone know how to do this?
>
> On Sep 21, 10:35 pm, Yo-Yo Ma  wrote:
>
>
>
> > I have a model with:
>
> > parent = ForeignKey('self', blank=True, null=True)
>
> > In that model I've overridden clean() to contain:
>
> > if self.parent:
> >     # Do some stuff
>
> > It raises an attribute error saying that parent.pk doesn't exist. How
> > can I get around this. Note that my foreign key is recursive.

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



Re: Problem with ForeignKey()

2010-09-22 Thread Yo-Yo Ma
Anyone know how to do this?

On Sep 21, 10:35 pm, Yo-Yo Ma  wrote:
> I have a model with:
>
> parent = ForeignKey('self', blank=True, null=True)
>
> In that model I've overridden clean() to contain:
>
> if self.parent:
>     # Do some stuff
>
> It raises an attribute error saying that parent.pk doesn't exist. How
> can I get around this. Note that my foreign key is recursive.

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



Problem with ForeignKey()

2010-09-21 Thread Yo-Yo Ma
I have a model with:

parent = ForeignKey('self', blank=True, null=True)

In that model I've overridden clean() to contain:

if self.parent:
# Do some stuff

It raises an attribute error saying that parent.pk doesn't exist. How
can I get around this. Note that my foreign key is recursive.

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



Re: Django Chat App?

2010-09-16 Thread Yo-Yo Ma
This might not be any help since I know nothing of VOIP, but for the
chat portion take a look in to Ape ( a comet server written in C ).

On Sep 16, 9:41 am, Sithembewena Lloyd Dube  wrote:
> Indeed it is, but the media server isn't :).
>
> On Thu, Sep 16, 2010 at 5:35 PM, esatterwh...@wi.rr.com <
>
>
>
> esatterwh...@wi.rr.com> wrote:
> > The Flex Framework is open source.
>
> > On Sep 16, 6:19 am, Sithembewena Lloyd Dube  wrote:
> > > Thanks Shamail! I should have mentioned that I actually need something
> > > open-source :)
>
> > > On Thu, Sep 16, 2010 at 12:16 PM, Shamail Tayyab  > >wrote:
>
> > > > On Thursday 16 September 2010 03:40 PM, Sithembewena Lloyd Dube wrote:
>
> > > >> Hi all,
>
> > > >> I will soon be working on a Django site that will incorporate a
> > heavily
> > > >> customised chat app. The client wants voip capability.
>
> > > >> I've had a look at the Twisted framework, but I need to know whether
> > or
> > > >> not there is anything else out there - perhaps tailored for use with
> > Django?
>
> > > >> --
> > > >> Regards,
> > > >> Sithembewena Lloyd Dube
> > > >>http://www.lloyddube.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-us...@googlegroups.com.
> > > >> To unsubscribe from this group, send email to
> > > >> django-users+unsubscr...@googlegroups.com
> > 
> > > >> .
> > > >> For more options, visit this group at
> > > >>http://groups.google.com/group/django-users?hl=en.
>
> > > > If its VoIP, your best bet would be to use flash, accompanied along
> > with a
> > > > media server, your chat can also work.
> > > > Reason: You need live streaming.
> > > > Wowza media server/Adobe FMS is what you should consider once.
>
> > > > Regards
>
> > > > --
> > > > Shamail Tayyab
> > > > Blog:http://shamail.in/blog
>
> > > > --
> > > > You received this message because you are subscribed to the Google
> > Groups
> > > > "Django users" group.
> > > > To post to this group, send email to django-us...@googlegroups.com.
> > > > To unsubscribe from this group, send email to
> > > > django-users+unsubscr...@googlegroups.com
> > 
> > > > .
> > > > For more options, visit this group at
> > > >http://groups.google.com/group/django-users?hl=en.
>
> > > --
> > > Regards,
> > > Sithembewena Lloyd Dubehttp://www.lloyddube.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-us...@googlegroups.com.
> > To unsubscribe from this group, send email to
> > django-users+unsubscr...@googlegroups.com
> > .
> > For more options, visit this group at
> >http://groups.google.com/group/django-users?hl=en.
>
> --
> Regards,
> Sithembewena Lloyd Dubehttp://www.lloyddube.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-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: How to pass in a file to a model directly

2010-09-15 Thread Yo-Yo Ma
Anyone?

On Sep 15, 1:18 pm, Yo-Yo Ma  wrote:
> I'm wondering how to do this:
>
> instance = SomeModelWithFile.objects.create(
>     file = some_file,
>     spam="Spam",
>     foo="Foo"
> )
>
> How can I manually pass in a file like this? In file=some_file should
> some_file be a FileUpload instance? How do I create one of those?

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



How to pass in a file to a model directly

2010-09-15 Thread Yo-Yo Ma
I'm wondering how to do this:


instance = SomeModelWithFile.objects.create(
file = some_file,
spam="Spam",
foo="Foo"
)

How can I manually pass in a file like this? In file=some_file should
some_file be a FileUpload instance? How do I create one of those?

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



Django Nav - is there anything similar that is actively maintained

2010-08-26 Thread Yo-Yo Ma
I haven't tried http://code.google.com/p/django-nav/ but I would
imagine that it probably has issues because it hasn't changed since
2007. Does anyone know if there is a very intuitive navigation helper
like this, but newer?

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



Building a generic list template - where should I start?

2010-08-25 Thread Yo-Yo Ma
I'm wanting to build out a list template that can display any list of
objects in this manor (pseudo code:

{% for thing in things %}

{{ thing.foo }}
{{ thing.bar }}
{{ thing.spam }}
{{ thing.eggs }}

{% endfor %}

The problem is, of course, that I want to list more than just "things"
using the same template. Things have "foo", "bar", "spam", and "eggs".
"Widgets" might only have "snafu", and "peanut_butter" attributes.

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



Re: Selling Django

2010-06-17 Thread Yo-Yo Ma
This thread shows a very prevalent side of most developers that makes
me ashamed to tell people that I'm a developer.

The OP is not saying that we should go out and advertise that Django
is a great CMS. In fact he spends half of his post making trying to
preemptively shut all the know-it-all folks up before they even start
with, "The problem with your post is... [insert ignoramus disguised as
b-rated philosophy]".

The fact of the matter is that the best software sometimes comes from
those who have no business sense (or any sense for that matter).
Django's community is very closed minded. For those of you who would
like to promote Django as awesome for building ['CMS', 'SOCIAL
APPLICATION', 'INSERT YOUR FAVORITE WHEEL TO REINVENT'], feel free to
do so. You're helping yourself, not the closed-minded folks. They
don't get jobs usually which is why they work for free.

In Summary: Great post/question. This is something I think that has to
be addressed by community members on their own, instead of relying on
core Django clique.



On Jun 17, 12:39 pm, Richard Shebora  wrote:
> Matt,
>
> Between you and Russ I see what you mean.  I will contact Tom and
> Venkatraman regarding their concept to see how I can help.  I am not
> proficient with django's paradigm yet, but I can get better in the
> process.
>
> Thanks,
> Richard Shebora
>
> On Thu, Jun 17, 2010 at 11:36 AM, Matt Hoskins  
> wrote:
> > Richard,
>
> > That is where most people who are looking for something *in that
> > space* look first - i.e. they have a set of requirements where those
> > platforms are a good fit for what they're trying to do, but it isn't
> > the only space. Those people aren't the people who pay my wages at
> > present because, as I said, I'm currently not building applications
> > where any of those would be a good fit :). I originally selected
> > Django because I was looking for something that was specifically not
> > in the space that, say, drupal is in as although some of the
> > facilities it and other vaguely similar frameworks provide could have
> > been of use, a lot of what they provided wasn't a good fit or was just
> > irrelevant and if using them I would have been forced into doing
> > things a less-than-ideal way.
>
> > As you got more specific in this thread your approach seemed to be
> > orientating towards "selling" Django by "selling" Django-based
> > applications of a certain type (a bit like "selling" Zope by "selling"
> > Plone, perhaps?) and thus the path to that being to sort out those
> > applications. I'm not saying it's not a valid approach (having great
> > re-usable applications is no bad thing), I'm just saying it's not the
> > only approach and that the space you talk about is not the only
> > requirement space where Django is useful.
>
> > Regards,
> > Matt
>
> > On Jun 17, 3:06 pm, Richard Shebora  wrote:
> >> @Matt
>
> >> You are correct.  The "drupal/joomla/plone/wordpress space" does exist
> >> and it is where most people (non-developers) look first.  These are
> >> the people who need to perceive django in a more positive light if the
> >> goal is to increase django market share.  They are the people who hire
> >> you and I.  If not, it's a moot point.
>
> > --
> > You received this message because you are subscribed to the Google Groups 
> > "Django users" group.
> > To post to this group, send email to django-us...@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.

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