Re: Best Practices for Migrations in Reusable Apps?

2015-06-10 Thread reduxionist
Wow, terrific and comprehensive answer (as usual) Carl, thanks! I'll adjust my 
approach accordingly, thanks very much!

-- 
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/dcd22073-1382-496e-8b3d-37f4f94a76b2%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Best Practices for Migrations in Reusable Apps?

2015-06-10 Thread reduxionist
I was afraid of that, glad I asked. Thanks for your input!

-- 
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/7d77a29f-7109-496e-b29e-cebd288f5573%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Keep selected option after form submission

2015-06-10 Thread James Schneider
Depending on how crazy you need to get, you may be able to get away
with just styling the widget instances in the Form or ModelForm
definition: 
https://docs.djangoproject.com/en/dev/ref/forms/widgets/#customizing-widget-instances

If you do want something crazy, you can also subclass the Select
widget to override the rendering as Vijay mentioned. The link above
has information on how to do that.

Alternatively, you can place the {% if %} statement inline and remove
the duplication, although its a bit more cumbersome to look at:


{{ name }}


Django handles the rendering of Select widgets (ie {{ form.activity
}}) directly in Python rather than passing it off to a template, but
the logic they use is similar to what you have specified in your
template code.

https://github.com/django/django/blob/1.8.2/django/forms/widgets.py#L508

-James

On Wed, Jun 10, 2015 at 10:36 AM,   wrote:
> OK, I will check this out. Thank you very much!
>
> Em quarta-feira, 10 de junho de 2015 14:31:17 UTC-3, Vijay Khemlani
> escreveu:
>>
>> Subclassing the django.forms.widgets.Select class and setting it as a
>> widget for the form field.
>>
>> On Wed, Jun 10, 2015 at 2:13 PM,  wrote:
>>>
>>> I decided to use {{ form.activity }} instead of that code above, but it
>>> is a bit strange, it should work in that way.
>>>
>>> Now, I'm using django-widget-tweaks
>>> (https://github.com/kmike/django-widget-tweaks) to add some attributes to
>>> selected tag and it's working.
>>>
>>> The reason why I wasn't this to render automatically is because it gets
>>> less customizable. For example: How would you add an attribute for each
>>> option in that select field?
>>>
>>>
>>> --
>>> 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...@googlegroups.com.
>>> To post to this group, send email to django...@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/1ec396fb-ff4b-43ea-8304-4a876bd56c35%40googlegroups.com.
>>>
>>> For more options, visit https://groups.google.com/d/optout.
>>
>>
> --
> 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/04dca7e9-4a8c-4717-b907-68f29f299127%40googlegroups.com.
>
> For more options, visit https://groups.google.com/d/optout.

-- 
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/CA%2Be%2BciWHiwo%3DW64AnWDWSan06yB1N1XE7mFAJYp50CR4-eGuHw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Best Practices for Migrations in Reusable Apps?

2015-06-10 Thread Carl Meyer
Hi Jonathan,

On 06/10/2015 12:24 AM, Jonathan Barratt wrote:
> I'm interested to know what the community's opinions are on how best
> to package migrations with reusable apps (I'm thinking of the
> built-in migrations, but it seems the same principles would apply for
> pre-1.8 south migrations).
> 
> My current approach is to squash all schema migrations each time a
> new one is generated so that new installs are smooth;

You can do this, but you should keep the old migrations around as well,
for the sake of your existing upgrading users. You should only remove
replaced migrations once you are confident that all your users (or
whatever percentage of them you care about) have upgraded.

The migration-squashing system is designed to make it easy to squash
migrations for new users but also keep the old ones around for upgrading
users; it automatically takes care of making sure the right migrations
are used in each case.

> we've seen
> issues arise from just keeping the individual migrations that
> accumulate the long way (in terms of both speed and bugs).

Speed can be an issue with lots of migrations; squashing migrations (but
keeping the old ones) addresses this.

Not much that can be said about bugs without specific examples. The
migration system has certainly had its share of bugs! Almost all the
ones we know about have been fixed. Your old set of migrations should
result in the exact same schema as the new squashed one. If it doesn't,
that's certainly a problem that needs to be fixed, in Django and/or in
one or more of the migration files.

> I figure existing users who upgrade can be expected to run their own
> make migrations if necessary, but perhaps I'm placing the burden of
> work on the wrong party...

This is placing the burden on the wrong party (and on many parties,
instead of one party), and it actually puts your upgrading users in
quite a pickle. They can't add migrations directly to your codebase
without forking it, which means their only recourse to add the necessary
migration is to set MIGRATION_MODULES to ignore your migrations entirely
and replace them with their own.

MIGRATION_MODULES is intended for rare cases, not routine use. Your app
should contain the necessary migrations for all your users, new and
upgrading. Failing to provide migrations that will work for upgrading
users means you miss out on all the benefits of migrations; you're
essentially returning to the old syncdb world, where no provision is
made for upgrades that include schema changes.

> If initial data is necessary, then it gets its own separate data
> migration - this seems to keep the code (and git history) cleaner
> IMO.
> 
> I'd greatly appreciate and criticism, suggestions or alternate
> approaches that occurs to you.
> 
> Thanks in advance, Jonathan

Hope that helps,

Carl

-- 
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/55788921.2020406%40oddbird.net.
For more options, visit https://groups.google.com/d/optout.


signature.asc
Description: OpenPGP digital signature


Re: How to DRY, define a set of model-fields and reuse them as multiple instances

2015-06-10 Thread ThomasTheDjangoFan
Hi Felix,

I just had a look at proxy models. Nice stuff, but it's not what I am 
looking for.

I need to be able to give each "instance" an individual value.

Hm




Am Mittwoch, 10. Juni 2015 19:17:07 UTC+2 schrieb felix:
>
>  El 10/06/15 12:33, ThomasTheDjangoFan escribió:
>  
> Hi Bruno,
>
> Abstract Base Models come close but they don't allow me to combine 
> multiple instances of the BaseModel in the DataHolderModel.
>
> My goal is to store them all in one table without having to manually add 
> all the fields.
>
> Any suggestions?
>
>
> Am Mittwoch, 10. Juni 2015 17:49:13 UTC+2 schrieb Bruno A.: 
>>
>> It looks like you want a Model to inherit from multiple base model? 
>> Multiple time from the same one, with different parameters?
>>
>> I'm not sure I understood what you are trying to do, but maybe abstract 
>> models can help you?
>>
>> https://docs.djangoproject.com/en/1.8/topics/db/models/#abstract-base-classes
>>
>>
>> On Tuesday, 9 June 2015 22:20:19 UTC+1, ThomasTheDjangoFan wrote: 
>>>
>>> Hi guys,
>>>
>>> now this is kind of hard for me to explain, I hope that somebody 
>>> understands what I actually want.
>>>
>>> I am a python newbie and wonder if there is an easy solution.
>>>
>>> *They say: DRY!!*
>>>
>>>
>>>
>>> *My question is: How do a define an (abstract?) class including methods 
>>> and fields and then attach it to a real mode with variants instants?*
>>>
>>> * The data needs to be available as realy models.* types, so I can use 
>>> it in forms.*
>>>
>>> Hopefully this example makes it clear:
>>>
>>>  
>>> # I would love to keep it DRY and wonder if there is a solution for this 
>>> in python?
>>>
>>> # NOW THIS IS TOTALLY MADE UP
>>> # Basically I would like to be able to define a definition of 
>>> model-fields and functions
>>> # and then be able to "attach" it to a model as various instances
>>> class KidType (models.Model):
>>> NAMEHOLDER = '' #nameholder
>>>
>>> NAMEHOLDER_text = models.TextField()
>>> NAMEHOLDER_timestamp_updated = models.DateTimeField(auto_now_add=
>>> False, auto_now=True)
>>>
>>> def example_function_shared_among_types():
>>> return str(self.NAMEHOLDER_text + self.
>>> NAMEHOLDER_timestamp_updated)
>>>
>>> def set_NAMEHOLDER_text(value):
>>> self.set_NAMEHOLDER_text(value)
>>>
>>> #
>>> class DataHolderModel(models.Model):
>>> # Attach the above definition with different names
>>> # and make them accessable
>>> @attach (KidType, KidType.NAME = 'dataset1')
>>> @attach (KidType, KidType.NAME = 'dataset2')
>>> @attach (KidType, KidType.NAME = 'dataset3')
>>>
>>> # Access the instances within the HolderModel:
>>> data_holder = DataHolderModel()
>>> data_holder.dataset1_text = 'value1'
>>> data_holder.set_dataset1_text('value1')
>>> data_holder.dataset2_text = 'value2'
>>> data_holder.dataset3_text = 'value3'
>>>  
>>> Any ideas? Can I do something like this?
>>>
>>> I am really thankful for your tips
>>> Thomas
>>>
>>>
>>>
>  If its the same data and maybe with different behaviour then proxy models 
> could be what you want.
>
>
> 

-- 
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/e422e01e-2517-4388-b4ca-6066644aeb28%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Have mercy please!

2015-06-10 Thread Carl Meyer
Hi Jon,

Thanks for sharing your experience.

On 06/09/2015 07:25 PM, Jon Foster wrote:
> I've been involved with Django, on and off, since v0.96 or so. I love
> Django and think its the most productive way to build rich websites with
> custom defined content types. Throw in Django-CMS and things get pretty
> darn cool.
> 
> I was thrilled when Django reached v1.0 since it came with the promise
> of having a consistent and stable API, specifically a lack of backwards
> incompatible changes, unless required by security concerns.
> Unfortunately this promise is routinely violated for various excuses.
> The bottom line is none of the apps I've written have been able to
> survive any 2 point upgrades (v+0.2). Single point upgrades usually only
> cause minor breakage.

This last confuses me, so I'd like to get clarity. If "single point
upgrades usually only cause minor breakage", then a two point upgrade is
just two single point upgrades, one after the other, correct?

Trying to upgrade directly from e.g. 1.6 to 1.8 without first going
through 1.7 - by which I mean "having a fully working site that passes
its tests with no deprecation warnings in 1.7" -- is definitely not
recommended.

So is the problem here that you've been trying to do a two-version
upgrade directly, instead of version-by-version? Or that "upgrade with
minor breakage" + "upgrade with minor breakage" = "too much for the
project to survive"?

> I realize the desire to grow things and I applaud it. But there is a
> business issue here. I can't, in good conscience recommend Django as a
> site platform to many of my small clients as they simply could not
> afford the upkeep of a Django powered site. Especially if the site is
> e-commerce related, where PCI, and responsible site operation, will
> require that we stay current. In order to do so would require staying up
> with the constant flow of backwards incompatible changes, combined with
> the time and effort to reverse engineer and maintain contributed apps,
> which aren't keeping pace either.
> 
> With the current method of development on the Django platform, if I had
> just a dozen sites of moderate complexity, it would become a full time
> job just keeping them updated. Its complicated enough just finding the
> apps that will actually work with each other to construct a site. But
> the carefully constructed house of cards is virtually guaranteed to
> break with the next update.
> 
> So I ask, PLEASE return to and stick with the promise of API stability?
> You promised and routinely point to that statement, while making
> backwards incompatible changes. I want to spend more time working with
> Django, but I need to know that my clients can rely on painless and cost
> effective upgrades.
> 
> Thanks for reading my complaint,
> Jon
> 
> -- 
> 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/11e78690-2b5f-4e99-a377-62c19b74e333%40googlegroups.com
> .
> For more options, visit https://groups.google.com/d/optout.

-- 
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/557886D1.9030608%40oddbird.net.
For more options, visit https://groups.google.com/d/optout.


signature.asc
Description: OpenPGP digital signature


Re: Keep selected option after form submission

2015-06-10 Thread julio . lacerda
OK, I will check this out. Thank you very much!

Em quarta-feira, 10 de junho de 2015 14:31:17 UTC-3, Vijay Khemlani 
escreveu:
>
> Subclassing the django.forms.widgets.Select class and setting it as a 
> widget for the form field.
>
> On Wed, Jun 10, 2015 at 2:13 PM, > 
> wrote:
>
>> I decided to use {{ form.activity }} instead of that code above, but it 
>> is a bit strange, it should work in that way.
>>
>> Now, I'm using django-widget-tweaks (
>> https://github.com/kmike/django-widget-tweaks) to add some attributes to 
>> selected tag and it's working.
>>
>> The reason why I wasn't this to render automatically is because it gets 
>> less customizable. For example: How would you add an attribute for each 
>> option in that select field?
>>  
>>
>> -- 
>> 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...@googlegroups.com .
>> To post to this group, send email to django...@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/1ec396fb-ff4b-43ea-8304-4a876bd56c35%40googlegroups.com
>>  
>> 
>> .
>>
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>

-- 
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/04dca7e9-4a8c-4717-b907-68f29f299127%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Keep selected option after form submission

2015-06-10 Thread Vijay Khemlani
Subclassing the django.forms.widgets.Select class and setting it as a
widget for the form field.

On Wed, Jun 10, 2015 at 2:13 PM,  wrote:

> I decided to use {{ form.activity }} instead of that code above, but it is
> a bit strange, it should work in that way.
>
> Now, I'm using django-widget-tweaks (
> https://github.com/kmike/django-widget-tweaks) to add some attributes to
> selected tag and it's working.
>
> The reason why I wasn't this to render automatically is because it gets
> less customizable. For example: How would you add an attribute for each
> option in that select field?
>
>
> --
> 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/1ec396fb-ff4b-43ea-8304-4a876bd56c35%40googlegroups.com
> 
> .
>
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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/CALn3ei2YiqV9%3DHU7d%3DCWEeD%3Df9-OUzuBVG8Dfx3Tg4GqPbcfeA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: How to DRY, define a set of model-fields and reuse them as multiple instances

2015-06-10 Thread felix

El 10/06/15 12:33, ThomasTheDjangoFan escribió:

Hi Bruno,

Abstract Base Models come close but they don't allow me to combine 
multiple instances of the BaseModel in the DataHolderModel.


My goal is to store them all in one table without having to manually 
add all the fields.


Any suggestions?


Am Mittwoch, 10. Juni 2015 17:49:13 UTC+2 schrieb Bruno A.:

It looks like you want a Model to inherit from multiple base
model? Multiple time from the same one, with different parameters?

I'm not sure I understood what you are trying to do, but maybe
abstract models can help you?

https://docs.djangoproject.com/en/1.8/topics/db/models/#abstract-base-classes




On Tuesday, 9 June 2015 22:20:19 UTC+1, ThomasTheDjangoFan wrote:

Hi guys,

now this is kind of hard for me to explain, I hope that
somebody understands what I actually want.

I am a python newbie and wonder if there is an easy solution.

/They say: DRY!!/

*My question is:
How do a define an (abstract?) class including methods and fields
and then attach it to a real mode with variants instants?*
*
The data needs to be available as realy models.* types, so I
can use it in forms.*

Hopefully this example makes it clear:

|

# I would love to keep it DRY and wonder if there is a
solution for this in python?

# NOW THIS IS TOTALLY MADE UP
# Basically I would like to be able to define a definition of
model-fields and functions
# and then be able to "attach" it to a model as various instances
classKidType(models.Model):
NAMEHOLDER =''#nameholder

NAMEHOLDER_text =models.TextField()
NAMEHOLDER_timestamp_updated
=models.DateTimeField(auto_now_add=False,auto_now=True)

defexample_function_shared_among_types():
returnstr(self.NAMEHOLDER_text +self.NAMEHOLDER_timestamp_updated)

defset_NAMEHOLDER_text(value):
self.set_NAMEHOLDER_text(value)

#
classDataHolderModel(models.Model):
# Attach the above definition with different names
# and make them accessable
@attach(KidType,KidType.NAME ='dataset1')
@attach(KidType,KidType.NAME ='dataset2')
@attach(KidType,KidType.NAME ='dataset3')

# Access the instances within the HolderModel:
data_holder =DataHolderModel()
data_holder.dataset1_text ='value1'
data_holder.set_dataset1_text('value1')
data_holder.dataset2_text ='value2'
data_holder.dataset3_text ='value3'
|

Any ideas? Can I do something like this?

I am really thankful for your tips
Thomas



If its the same data and maybe with different behaviour then proxy 
models could be what you want.



--
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/557871F8.3050509%40epepm.cupet.cu.
For more options, visit https://groups.google.com/d/optout.


Re: Keep selected option after form submission

2015-06-10 Thread julio . lacerda
I decided to use {{ form.activity }} instead of that code above, but it is 
a bit strange, it should work in that way.

Now, I'm using django-widget-tweaks 
(https://github.com/kmike/django-widget-tweaks) to add some attributes to 
selected tag and it's working.

The reason why I wasn't this to render automatically is because it gets 
less customizable. For example: How would you add an attribute for each 
option in that select field?
 

-- 
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/1ec396fb-ff4b-43ea-8304-4a876bd56c35%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: How to DRY, define a set of model-fields and reuse them as multiple instances

2015-06-10 Thread ThomasTheDjangoFan
Hi Bruno,

Abstract Base Models come close but they don't allow me to combine multiple 
instances of the BaseModel in the DataHolderModel.

My goal is to store them all in one table without having to manually add 
all the fields.

Any suggestions?


Am Mittwoch, 10. Juni 2015 17:49:13 UTC+2 schrieb Bruno A.:
>
> It looks like you want a Model to inherit from multiple base model? 
> Multiple time from the same one, with different parameters?
>
> I'm not sure I understood what you are trying to do, but maybe abstract 
> models can help you?
>
> https://docs.djangoproject.com/en/1.8/topics/db/models/#abstract-base-classes
>
>
> On Tuesday, 9 June 2015 22:20:19 UTC+1, ThomasTheDjangoFan wrote:
>>
>> Hi guys,
>>
>> now this is kind of hard for me to explain, I hope that somebody 
>> understands what I actually want.
>>
>> I am a python newbie and wonder if there is an easy solution.
>>
>> *They say: DRY!!*
>>
>>
>>
>> *My question is:How do a define an (abstract?) class including methods 
>> and fieldsand then attach it to a real mode with variants instants?*
>>
>> *The data needs to be available as realy models.* types, so I can use it 
>> in forms.*
>>
>> Hopefully this example makes it clear:
>>
>>
>> # I would love to keep it DRY and wonder if there is a solution for this 
>> in python?
>>
>> # NOW THIS IS TOTALLY MADE UP
>> # Basically I would like to be able to define a definition of 
>> model-fields and functions
>> # and then be able to "attach" it to a model as various instances
>> class KidType (models.Model):
>> NAMEHOLDER = '' #nameholder
>>
>> NAMEHOLDER_text = models.TextField()
>> NAMEHOLDER_timestamp_updated = models.DateTimeField(auto_now_add=
>> False, auto_now=True)
>>
>> def example_function_shared_among_types():
>> return str(self.NAMEHOLDER_text + self.
>> NAMEHOLDER_timestamp_updated)
>>
>> def set_NAMEHOLDER_text(value):
>> self.set_NAMEHOLDER_text(value)
>>
>> #
>> class DataHolderModel(models.Model):
>> # Attach the above definition with different names
>> # and make them accessable
>> @attach (KidType, KidType.NAME = 'dataset1')
>> @attach (KidType, KidType.NAME = 'dataset2')
>> @attach (KidType, KidType.NAME = 'dataset3')
>>
>> # Access the instances within the HolderModel:
>> data_holder = DataHolderModel()
>> data_holder.dataset1_text = 'value1'
>> data_holder.set_dataset1_text('value1')
>> data_holder.dataset2_text = 'value2'
>> data_holder.dataset3_text = 'value3'
>>
>> Any ideas? Can I do something like this?
>>
>> I am really thankful for your tips
>> Thomas
>>
>>
>>

-- 
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/90a7b0f2-9565-424f-8c64-4c6e720f6223%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: How to DRY, define a set of model-fields and reuse them as multiple instances

2015-06-10 Thread Bruno A.
It looks like you want a Model to inherit from multiple base model? 
Multiple time from the same one, with different parameters?

I'm not sure I understood what you are trying to do, but maybe abstract 
models can help you?
https://docs.djangoproject.com/en/1.8/topics/db/models/#abstract-base-classes


On Tuesday, 9 June 2015 22:20:19 UTC+1, ThomasTheDjangoFan wrote:
>
> Hi guys,
>
> now this is kind of hard for me to explain, I hope that somebody 
> understands what I actually want.
>
> I am a python newbie and wonder if there is an easy solution.
>
> *They say: DRY!!*
>
>
>
> *My question is:How do a define an (abstract?) class including methods and 
> fieldsand then attach it to a real mode with variants instants?*
>
> *The data needs to be available as realy models.* types, so I can use it 
> in forms.*
>
> Hopefully this example makes it clear:
>
>
> # I would love to keep it DRY and wonder if there is a solution for this 
> in python?
>
> # NOW THIS IS TOTALLY MADE UP
> # Basically I would like to be able to define a definition of model-fields 
> and functions
> # and then be able to "attach" it to a model as various instances
> class KidType (models.Model):
> NAMEHOLDER = '' #nameholder
>
> NAMEHOLDER_text = models.TextField()
> NAMEHOLDER_timestamp_updated = models.DateTimeField(auto_now_add=False
> , auto_now=True)
>
> def example_function_shared_among_types():
> return str(self.NAMEHOLDER_text + self.
> NAMEHOLDER_timestamp_updated)
>
> def set_NAMEHOLDER_text(value):
> self.set_NAMEHOLDER_text(value)
>
> #
> class DataHolderModel(models.Model):
> # Attach the above definition with different names
> # and make them accessable
> @attach (KidType, KidType.NAME = 'dataset1')
> @attach (KidType, KidType.NAME = 'dataset2')
> @attach (KidType, KidType.NAME = 'dataset3')
>
> # Access the instances within the HolderModel:
> data_holder = DataHolderModel()
> data_holder.dataset1_text = 'value1'
> data_holder.set_dataset1_text('value1')
> data_holder.dataset2_text = 'value2'
> data_holder.dataset3_text = 'value3'
>
> Any ideas? Can I do something like this?
>
> I am really thankful for your tips
> Thomas
>
>
>

-- 
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/8dc5d6cd-3852-4d82-b1b7-15682be10992%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Where is the best place to get assistance installing Red Hat, Oracle and Django onto a VPN?

2015-06-10 Thread Frank Bieniek
This Article might help:
Django, Redis, Postgres, DataVolume in a Docker Environment:
https://realpython.com/blog/python/django-development-with-docker-compose-and-machine/

-- 
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/578d7bc3-005b-436d-9e52-2d0f49185a09%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: "RuntimeError: Error creating new content types."

2015-06-10 Thread Devang Mundhra
In my case this is not a Django bug.
The problem was that since 1.8 contenttypes started to have migrations. But
since the table already existed earlier, the migrations needed to be faked.
When faking the migrations, I used python manage.py migrate contenttypes
--fake which faked both 0001 and 0002.

The fix was to remove the fake migration for 0002 from django_migrations
table and then do the actual migration.

On Wed, Jun 10, 2015 at 6:57 AM Tim Graham  wrote:

> If anyone running into this problem can figure out why the
> contrib.contenttypes migration (0002_remove_content_type_name) is being
> marked as applied but not actually run in the database, that will help
> determine if this is a bug in Django or a problem elsewhere.
>
>
> On Wednesday, June 10, 2015 at 7:11:48 AM UTC-4, Devang Mundhra wrote:
>>
>> I am getting the same error on Django v1.8.2 after migrating from v1.7.7
>> The underlying error is this-
>>
>> django.db.utils.IntegrityError: null value in column "name" violates not-
>>> null constraint
>>> DETAIL:  Failing row contains (39, null, app_name, model_name).
>>>
>>>
>> On Friday, April 17, 2015 at 1:25:06 PM UTC-7, Tim Graham wrote:
>>>
>>> The contenttypes name column was removed in Django 1.8. Could you
>>> retrieve the underlying exception before the RuntimeError is raised?
>>>
>>> On Friday, April 17, 2015 at 2:55:07 PM UTC-4, Christophe Pettus wrote:

 Digging into this a bit more, the specific exception is that it is
 trying to insert a contenttypes row with a null 'name' value.

 The code in question is doing a get_or_create() on the contenttype
 object.  I assume it should be picking up the name from the name @property
 on the ContentType model, but I don't see that ever actually being called.


 On Apr 17, 2015, at 11:24 AM, Christophe Pettus 
 wrote:

 > On Django 1.8, I'm encountering this error when attempting to apply
 migrations on the production system.  What's interesting is that it works
 fine on the dev system, and inspecting the django_migrations table, I don't
 see any (meaningful) differences between them (error text below).
 >
 > There was a model added to the "catalog" application which is not
 being created in django_content_type.
 >
 > Manually migrating contenttypes individually generates the same
 error.
 >
 > --
 >
 > $ python manage.py migrate
 > Operations to perform:
 >  Synchronize unmigrated apps: staticfiles, util, treebeard, messages,
 office
 >  Apply all migrations: info, customers, sessions, admin,
 contenttypes, auth, sites, catalog, coming_soon, orders
 > Synchronizing apps without migrations:
 >  Creating tables...
 >Running deferred SQL...
 >  Installing custom SQL...
 > Running migrations:
 >  Rendering model states... DONE
 >  Applying auth.0006_require_contenttypes_0002... OK
 > Traceback (most recent call last):
 >  File "manage.py", line 10, in 
 >execute_from_command_line(sys.argv)
 >  File
 "/home/tbc/environments/fugu/local/lib/python2.7/site-packages/django/core/management/__init__.py",
 line 338, in execute_from_command_line
 >utility.execute()
 >  File
 "/home/tbc/environments/fugu/local/lib/python2.7/site-packages/django/core/management/__init__.py",
 line 330, in execute
 >self.fetch_command(subcommand).run_from_argv(self.argv)
 >  File
 "/home/tbc/environments/fugu/local/lib/python2.7/site-packages/django/core/management/base.py",
 line 390, in run_from_argv
 >self.execute(*args, **cmd_options)
 >  File
 "/home/tbc/environments/fugu/local/lib/python2.7/site-packages/django/core/management/base.py",
 line 441, in execute
 >output = self.handle(*args, **options)
 >  File
 "/home/tbc/environments/fugu/local/lib/python2.7/site-packages/django/core/management/commands/migrate.py",
 line 225, in handle
 >emit_post_migrate_signal(created_models, self.verbosity,
 self.interactive, connection.alias)
 >  File
 "/home/tbc/environments/fugu/local/lib/python2.7/site-packages/django/core/management/sql.py",
 line 280, in emit_post_migrate_signal
 >using=db)
 >  File
 "/home/tbc/environments/fugu/local/lib/python2.7/site-packages/django/dispatch/dispatcher.py",
 line 201, in send
 >response = receiver(signal=self, sender=sender, **named)
 >  File
 "/home/tbc/environments/fugu/local/lib/python2.7/site-packages/django/contrib/auth/management/__init__.py",
 line 82, in create_permissions
 >ctype = ContentType.objects.db_manager(using).get_for_model(klass)
 >  File
 "/home/tbc/environments/fugu/local/lib/python2.7/site-packages/django/contrib/contenttypes/models.py",
 line 78, in get_for_model
 >"Error creating new content types. Please make sure contenttypes "
 > RuntimeError: Error creating new

Re: "RuntimeError: Error creating new content types."

2015-06-10 Thread Tim Graham
If anyone running into this problem can figure out why the 
contrib.contenttypes migration (0002_remove_content_type_name) is being 
marked as applied but not actually run in the database, that will help 
determine if this is a bug in Django or a problem elsewhere.

On Wednesday, June 10, 2015 at 7:11:48 AM UTC-4, Devang Mundhra wrote:
>
> I am getting the same error on Django v1.8.2 after migrating from v1.7.7
> The underlying error is this-
>
> django.db.utils.IntegrityError: null value in column "name" violates not-
>> null constraint
>> DETAIL:  Failing row contains (39, null, app_name, model_name).
>>
>>
> On Friday, April 17, 2015 at 1:25:06 PM UTC-7, Tim Graham wrote:
>>
>> The contenttypes name column was removed in Django 1.8. Could you 
>> retrieve the underlying exception before the RuntimeError is raised?
>>
>> On Friday, April 17, 2015 at 2:55:07 PM UTC-4, Christophe Pettus wrote:
>>>
>>> Digging into this a bit more, the specific exception is that it is 
>>> trying to insert a contenttypes row with a null 'name' value. 
>>>
>>> The code in question is doing a get_or_create() on the contenttype 
>>> object.  I assume it should be picking up the name from the name @property 
>>> on the ContentType model, but I don't see that ever actually being called. 
>>>
>>>
>>> On Apr 17, 2015, at 11:24 AM, Christophe Pettus  
>>> wrote: 
>>>
>>> > On Django 1.8, I'm encountering this error when attempting to apply 
>>> migrations on the production system.  What's interesting is that it works 
>>> fine on the dev system, and inspecting the django_migrations table, I don't 
>>> see any (meaningful) differences between them (error text below). 
>>> > 
>>> > There was a model added to the "catalog" application which is not 
>>> being created in django_content_type. 
>>> > 
>>> > Manually migrating contenttypes individually generates the same error. 
>>> > 
>>> > -- 
>>> > 
>>> > $ python manage.py migrate 
>>> > Operations to perform: 
>>> >  Synchronize unmigrated apps: staticfiles, util, treebeard, messages, 
>>> office 
>>> >  Apply all migrations: info, customers, sessions, admin, contenttypes, 
>>> auth, sites, catalog, coming_soon, orders 
>>> > Synchronizing apps without migrations: 
>>> >  Creating tables... 
>>> >Running deferred SQL... 
>>> >  Installing custom SQL... 
>>> > Running migrations: 
>>> >  Rendering model states... DONE 
>>> >  Applying auth.0006_require_contenttypes_0002... OK 
>>> > Traceback (most recent call last): 
>>> >  File "manage.py", line 10, in  
>>> >execute_from_command_line(sys.argv) 
>>> >  File 
>>> "/home/tbc/environments/fugu/local/lib/python2.7/site-packages/django/core/management/__init__.py",
>>>  
>>> line 338, in execute_from_command_line 
>>> >utility.execute() 
>>> >  File 
>>> "/home/tbc/environments/fugu/local/lib/python2.7/site-packages/django/core/management/__init__.py",
>>>  
>>> line 330, in execute 
>>> >self.fetch_command(subcommand).run_from_argv(self.argv) 
>>> >  File 
>>> "/home/tbc/environments/fugu/local/lib/python2.7/site-packages/django/core/management/base.py",
>>>  
>>> line 390, in run_from_argv 
>>> >self.execute(*args, **cmd_options) 
>>> >  File 
>>> "/home/tbc/environments/fugu/local/lib/python2.7/site-packages/django/core/management/base.py",
>>>  
>>> line 441, in execute 
>>> >output = self.handle(*args, **options) 
>>> >  File 
>>> "/home/tbc/environments/fugu/local/lib/python2.7/site-packages/django/core/management/commands/migrate.py",
>>>  
>>> line 225, in handle 
>>> >emit_post_migrate_signal(created_models, self.verbosity, 
>>> self.interactive, connection.alias) 
>>> >  File 
>>> "/home/tbc/environments/fugu/local/lib/python2.7/site-packages/django/core/management/sql.py",
>>>  
>>> line 280, in emit_post_migrate_signal 
>>> >using=db) 
>>> >  File 
>>> "/home/tbc/environments/fugu/local/lib/python2.7/site-packages/django/dispatch/dispatcher.py",
>>>  
>>> line 201, in send 
>>> >response = receiver(signal=self, sender=sender, **named) 
>>> >  File 
>>> "/home/tbc/environments/fugu/local/lib/python2.7/site-packages/django/contrib/auth/management/__init__.py",
>>>  
>>> line 82, in create_permissions 
>>> >ctype = ContentType.objects.db_manager(using).get_for_model(klass) 
>>> >  File 
>>> "/home/tbc/environments/fugu/local/lib/python2.7/site-packages/django/contrib/contenttypes/models.py",
>>>  
>>> line 78, in get_for_model 
>>> >"Error creating new content types. Please make sure contenttypes " 
>>> > RuntimeError: Error creating new content types. Please make sure 
>>> contenttypes is migrated before trying to migrate apps individually. 
>>> > -- 
>>> > -- Christophe Pettus 
>>> >   x...@thebuild.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...@googlegroups.com. 
>>> > To post to this group, se

How to develop/include a Django custom reusable app in a new project? Are there some guidelines?

2015-06-10 Thread Gustavo Adolfo Velasco Hernández
Hi everyone,

I create this question on Stackoverflow about some doubts I have on 
Django apps development process. Please visit 
http://stackoverflow.com/questions/30743720/how-to-develop-include-a-django-custom-reusable-app-in-a-new-project-are-there

Thanks in advance.

-- 
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/76092902-ed04-4adf-ae5f-1bda24afab42%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Where is the best place to get assistance installing Red Hat, Oracle and Django onto a VPN?

2015-06-10 Thread Kurtis Mullins
I would also recommend checking out Heroku for a quicker test release. Down the 
line, when you want more control over the system administration, you can save a 
bit of money by building out your own services.

> On Jun 10, 2015, at 8:35 AM, Vijay Khemlani  wrote:
> 
> Wihtout knowing anything about your project, I think going RedHat + Oracle 
> might be a bit overkill, especially Oracle since it is a mess to configure 
> and tune.
> 
> Have you considered CentOS as an alternative? same binaries and libraries as 
> RedHat but completely free, and also easier to deploy in the typical VPS 
> providers (Linode, DigitalOcean, etc). For the database PostgreSQL is solid 
> and (kinda) simple to deploy and configure.
> 
> 
>> On Wed, Jun 10, 2015 at 7:36 AM, Jason  wrote:
>> We are a group of developers that are reasonable new to the Django web 
>> framework. We've managed to build an application that is currently housed in 
>> PythonAnywhere and are now at the stage where we would like to conduct some 
>> performance testing.
>> 
>> Our current plan is to rent some space from a VPN provider with 
>> production-like specs and start testing the performance of our application. 
>> However, whilst we are reasonably capable at building our application, we 
>> are new to the deployment of things in Virtual environments (including OS, 
>> database software etc...).
>> 
>> We are planning to use Red Hat Linux for the OS and an Oracle database for 
>> the initial deployment and would appreciate any ideas on how to go about 
>> gaining some assistance with this. To start with, we are planning to have 
>> the application code and the database under one virtual server and later on 
>> we will test the separation of the database and the application code.
>> -- 
>> 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/c4e4dbd6-c50c-41b3-92c3-5d9d6ba8472e%40googlegroups.com.
>> For more options, visit https://groups.google.com/d/optout.
> 
> -- 
> 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/CALn3ei1YQN1f78w6_COm2JcoDLgyPGry5%2BYc%3D6tuXhWPrEhBLg%40mail.gmail.com.
> For more options, visit https://groups.google.com/d/optout.

-- 
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/6AB5A293-E70A-459A-95E0-A42A09D12447%40gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Where is the best place to get assistance installing Red Hat, Oracle and Django onto a VPN?

2015-06-10 Thread Vijay Khemlani
Wihtout knowing anything about your project, I think going RedHat + Oracle
might be a bit overkill, especially Oracle since it is a mess to configure
and tune.

Have you considered CentOS as an alternative? same binaries and libraries
as RedHat but completely free, and also easier to deploy in the typical VPS
providers (Linode, DigitalOcean, etc). For the database PostgreSQL is solid
and (kinda) simple to deploy and configure.


On Wed, Jun 10, 2015 at 7:36 AM, Jason  wrote:

> We are a group of developers that are reasonable new to the Django web
> framework. We've managed to build an application that is currently housed
> in PythonAnywhere and are now at the stage where we would like to conduct
> some performance testing.
>
> Our current plan is to rent some space from a VPN provider with
> production-like specs and start testing the performance of our application.
> However, whilst we are reasonably capable at building our application, we
> are new to the deployment of things in Virtual environments (including OS,
> database software etc...).
>
> We are planning to use Red Hat Linux for the OS and an Oracle database for
> the initial deployment and would appreciate any ideas on how to go about
> gaining some assistance with this. To start with, we are planning to have
> the application code and the database under one virtual server and later on
> we will test the separation of the database and the application code.
>
> --
> 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/c4e4dbd6-c50c-41b3-92c3-5d9d6ba8472e%40googlegroups.com
> 
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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/CALn3ei1YQN1f78w6_COm2JcoDLgyPGry5%2BYc%3D6tuXhWPrEhBLg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Presenting percents of Model values in simple templates?

2015-06-10 Thread Vijay Khemlani
You can add methods to your model class

class Container(models.Model):
name = models.CharField(max_length=128)
capacity = models.IntegerField()
contains = models.IntegerField()

def usage_percentage():
return 100.0 * self.contains / self.capacity

And in your template

{% if object_list %}

{% for o in object_list %}

{{ o.name }} {{ o.capacity }} {{ o.contains
}}  {{ o.usage_percentage }} 

{% endfor %}

{% endif %}

On Tue, Jun 9, 2015 at 11:03 PM, JLeary 
wrote:

> Hi.
> Total Django Newbie here... and pretty new to Python too.
> Anyway, I have this simple problem, and I've been reading documentation
> all afternoon but just can't come up with a simple solution.
>
> How can I display calculated values from the Model vales store in the
> database?
> Like, a percentage of two numbers?
>
> For instance;
>
> # myapp/models.py
> class Container(models.Model):
> name = models.CharField(max_length=128)
> capacity = models.IntegerField()
> contains = models.IntegerField()
>
>
> python manage.py shell
> >>> Container(name="big bucket", capacity=100, contains=22).save()
> >>> Container(name="small bucket", capacity=50, contains=48).save()
> >>> Container(name="medium bucket", capacity=75, contains=13).save()
>
>
> # myapp/views.py
> from django.http import HttpResponse
> from django.template import RequestContext, loader
> from .models import Container
> def index(request):
> object_list = Container.objects.all()
> template = loader.get_template('myapp/index.html')
> context = RequestContext(request, {
> 'object_list': object_list,
> })
> return HttpResponse(template.render(context))
>
>
> # myapp/templates/myapp/index.html
> {% if object_list %}
> 
> {% for o in object_list %}
> 
> {{ o.name }} {{ o.capacity }} {{ o.contains
> }}
> 
> {% endfor %}
> 
> {% endif %}
>
> .
>
>
> So, all is fine when I create a simple view template to display the NAME,
> CAPACITY, and CONTAINS info for each object.
>
> What I really want... is the Percent-Full of each Container to be
> displayed.
> But, I'm stumped as to how I can do this.
>
> I've tried creating a sub-class of Container, that contained methods to
> return the percentages, but was unable to get it to work.
>
> Any input is appreciated.
> Thanks.
>
>  --
> 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/386ecbdd-79e1-4646-b444-c5cd559ceb24%40googlegroups.com
> 
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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/CALn3ei0w87PR0NPu3rU4xua_YLdwk190JitCuo%3Dz-AtW06hpWg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: "RuntimeError: Error creating new content types."

2015-06-10 Thread Devang Mundhra
I am getting the same error on Django v1.8.2 after migrating from v1.7.7
The underlying error is this-

django.db.utils.IntegrityError: null value in column "name" violates not-
> null constraint
> DETAIL:  Failing row contains (39, null, app_name, model_name).
>
>
On Friday, April 17, 2015 at 1:25:06 PM UTC-7, Tim Graham wrote:
>
> The contenttypes name column was removed in Django 1.8. Could you retrieve 
> the underlying exception before the RuntimeError is raised?
>
> On Friday, April 17, 2015 at 2:55:07 PM UTC-4, Christophe Pettus wrote:
>>
>> Digging into this a bit more, the specific exception is that it is trying 
>> to insert a contenttypes row with a null 'name' value. 
>>
>> The code in question is doing a get_or_create() on the contenttype 
>> object.  I assume it should be picking up the name from the name @property 
>> on the ContentType model, but I don't see that ever actually being called. 
>>
>>
>> On Apr 17, 2015, at 11:24 AM, Christophe Pettus  
>> wrote: 
>>
>> > On Django 1.8, I'm encountering this error when attempting to apply 
>> migrations on the production system.  What's interesting is that it works 
>> fine on the dev system, and inspecting the django_migrations table, I don't 
>> see any (meaningful) differences between them (error text below). 
>> > 
>> > There was a model added to the "catalog" application which is not being 
>> created in django_content_type. 
>> > 
>> > Manually migrating contenttypes individually generates the same error. 
>> > 
>> > -- 
>> > 
>> > $ python manage.py migrate 
>> > Operations to perform: 
>> >  Synchronize unmigrated apps: staticfiles, util, treebeard, messages, 
>> office 
>> >  Apply all migrations: info, customers, sessions, admin, contenttypes, 
>> auth, sites, catalog, coming_soon, orders 
>> > Synchronizing apps without migrations: 
>> >  Creating tables... 
>> >Running deferred SQL... 
>> >  Installing custom SQL... 
>> > Running migrations: 
>> >  Rendering model states... DONE 
>> >  Applying auth.0006_require_contenttypes_0002... OK 
>> > Traceback (most recent call last): 
>> >  File "manage.py", line 10, in  
>> >execute_from_command_line(sys.argv) 
>> >  File 
>> "/home/tbc/environments/fugu/local/lib/python2.7/site-packages/django/core/management/__init__.py",
>>  
>> line 338, in execute_from_command_line 
>> >utility.execute() 
>> >  File 
>> "/home/tbc/environments/fugu/local/lib/python2.7/site-packages/django/core/management/__init__.py",
>>  
>> line 330, in execute 
>> >self.fetch_command(subcommand).run_from_argv(self.argv) 
>> >  File 
>> "/home/tbc/environments/fugu/local/lib/python2.7/site-packages/django/core/management/base.py",
>>  
>> line 390, in run_from_argv 
>> >self.execute(*args, **cmd_options) 
>> >  File 
>> "/home/tbc/environments/fugu/local/lib/python2.7/site-packages/django/core/management/base.py",
>>  
>> line 441, in execute 
>> >output = self.handle(*args, **options) 
>> >  File 
>> "/home/tbc/environments/fugu/local/lib/python2.7/site-packages/django/core/management/commands/migrate.py",
>>  
>> line 225, in handle 
>> >emit_post_migrate_signal(created_models, self.verbosity, 
>> self.interactive, connection.alias) 
>> >  File 
>> "/home/tbc/environments/fugu/local/lib/python2.7/site-packages/django/core/management/sql.py",
>>  
>> line 280, in emit_post_migrate_signal 
>> >using=db) 
>> >  File 
>> "/home/tbc/environments/fugu/local/lib/python2.7/site-packages/django/dispatch/dispatcher.py",
>>  
>> line 201, in send 
>> >response = receiver(signal=self, sender=sender, **named) 
>> >  File 
>> "/home/tbc/environments/fugu/local/lib/python2.7/site-packages/django/contrib/auth/management/__init__.py",
>>  
>> line 82, in create_permissions 
>> >ctype = ContentType.objects.db_manager(using).get_for_model(klass) 
>> >  File 
>> "/home/tbc/environments/fugu/local/lib/python2.7/site-packages/django/contrib/contenttypes/models.py",
>>  
>> line 78, in get_for_model 
>> >"Error creating new content types. Please make sure contenttypes " 
>> > RuntimeError: Error creating new content types. Please make sure 
>> contenttypes is migrated before trying to migrate apps individually. 
>> > -- 
>> > -- Christophe Pettus 
>> >   x...@thebuild.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...@googlegroups.com. 
>> > To post to this group, send email to django...@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/84FEBC7D-9A57-47FA-9429-A834A2F03021%40thebuild.com.
>>  
>>
>> > For more options, visit https://groups.google.com/d/optout. 
>>
>> -- 
>> -- Christophe Pettus 
>>x...@thebuild.com 
>>
>>

-- 
You received this message because you are subscri

Presenting percents of Model values in simple templates?

2015-06-10 Thread JLeary
Hi.
Total Django Newbie here... and pretty new to Python too.
Anyway, I have this simple problem, and I've been reading documentation all 
afternoon but just can't come up with a simple solution.

How can I display calculated values from the Model vales store in the 
database?
Like, a percentage of two numbers?

For instance;

# myapp/models.py 
class Container(models.Model):
name = models.CharField(max_length=128)
capacity = models.IntegerField()
contains = models.IntegerField()
   
   
python manage.py shell
>>> Container(name="big bucket", capacity=100, contains=22).save()
>>> Container(name="small bucket", capacity=50, contains=48).save()
>>> Container(name="medium bucket", capacity=75, contains=13).save()


# myapp/views.py
from django.http import HttpResponse
from django.template import RequestContext, loader
from .models import Container
def index(request):
object_list = Container.objects.all()
template = loader.get_template('myapp/index.html')
context = RequestContext(request, {
'object_list': object_list,
})
return HttpResponse(template.render(context))

   
# myapp/templates/myapp/index.html
{% if object_list %}

{% for o in object_list %}

{{ o.name }} {{ o.capacity }} {{ o.contains 
}}

{% endfor %}

{% endif %}

.


So, all is fine when I create a simple view template to display the NAME, 
CAPACITY, and CONTAINS info for each object.

What I really want... is the Percent-Full of each Container to be 
displayed. 
But, I'm stumped as to how I can do this.

I've tried creating a sub-class of Container, that contained methods to 
return the percentages, but was unable to get it to work.

Any input is appreciated.
Thanks.

-- 
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/386ecbdd-79e1-4646-b444-c5cd559ceb24%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Test cases fail with authentication against REMOTE_USER with normal auth fallback

2015-06-10 Thread Gergely Polonkai
Hello,

I was trying to follow
https://docs.djangoproject.com/en/1.8/howto/auth-remote-user/.

If I enable django.contrib.auth.middleware.RemoteUserMiddleware, even if I
set AUTHENTICATION_BACKEND to contain both RemoteUserBackend and
ModelBackend, my test cases stop working. However, using the runserver
environment, everything looks just fine regardless if I have REMOTE_USER
set (and I get logged in successfully with REMOTE_USER set to the correct
value).

Do I have to change anything in my tests for this to work?

For the record, I use django_webtest for most of my tests.

Best,
Gergely

-- 
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/CACczBUJAoqnEPY4z0yKqHN74fJOxCrrdhb_GtAQY7WTxc%2B3u%3DA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Simulating REMOTE_USER login with the test server

2015-06-10 Thread Gergely Polonkai
That’s exactly what I was doing, just haven’t had the time yet to share my
experience :)

2015-06-10 11:55 GMT+02:00 'Tom Evans' via Django users <
django-users@googlegroups.com>:

> On Tue, Jun 9, 2015 at 10:07 PM, Gergely Polonkai 
> wrote:
> > Hello,
> >
> > I’m about to use the test server with REMOTE_USER based logins. I already
> > know how to set it up with my Apache based server, but I can see no way
> of
> > doing the same with the dev server (manage.py runserver). I have tried
> > setting the environment variable REMOTE_USER to a desired value, as I saw
> > some env vars in request.META earlier, but it doesn’t seem to help. Does
> > anybody know if this is possible, and if so, how?
> >
> > Best,
> > Gergely
> >
>
> Write a piece of custom middleware that is only active with DEBUG=True
> that sets the REMOTE_USER you desire.
>
> 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.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/CAFHbX1Lv6XyBuj6_Xy%3DGSC3g-tndH77Z9oD3QdPUNHk9PLqLqA%40mail.gmail.com
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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/CACczBU%2Bu_h1d5F2qBYWfvHgB_Tgc2NoDNkcw1WPXs_ww0Y%3DXww%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Where is the best place to get assistance installing Red Hat, Oracle and Django onto a VPN?

2015-06-10 Thread Jason
We are a group of developers that are reasonable new to the Django web 
framework. We've managed to build an application that is currently housed 
in PythonAnywhere and are now at the stage where we would like to conduct 
some performance testing.

Our current plan is to rent some space from a VPN provider with 
production-like specs and start testing the performance of our application. 
However, whilst we are reasonably capable at building our application, we 
are new to the deployment of things in Virtual environments (including OS, 
database software etc...).

We are planning to use Red Hat Linux for the OS and an Oracle database for 
the initial deployment and would appreciate any ideas on how to go about 
gaining some assistance with this. To start with, we are planning to have 
the application code and the database under one virtual server and later on 
we will test the separation of the database and the application code.

-- 
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/c4e4dbd6-c50c-41b3-92c3-5d9d6ba8472e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Simulating REMOTE_USER login with the test server

2015-06-10 Thread 'Tom Evans' via Django users
On Tue, Jun 9, 2015 at 10:07 PM, Gergely Polonkai  wrote:
> Hello,
>
> I’m about to use the test server with REMOTE_USER based logins. I already
> know how to set it up with my Apache based server, but I can see no way of
> doing the same with the dev server (manage.py runserver). I have tried
> setting the environment variable REMOTE_USER to a desired value, as I saw
> some env vars in request.META earlier, but it doesn’t seem to help. Does
> anybody know if this is possible, and if so, how?
>
> Best,
> Gergely
>

Write a piece of custom middleware that is only active with DEBUG=True
that sets the REMOTE_USER you desire.

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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAFHbX1Lv6XyBuj6_Xy%3DGSC3g-tndH77Z9oD3QdPUNHk9PLqLqA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Adding language to url of an already multilingual site

2015-06-10 Thread Linux4Bene
Hi,


I created a multi lingual site in Django 1.7.1 where the user can change 
the language by means of a dropdown menu at the top of the site.
The urls are www.site.com/page. The page view checks the language, and 
then loads the correct templates which are named the same as the page.
The template is in a directory of its own and to find it, I only need to 
do this: template = 'template_subdir/{}.html'.format(page)

This works great but might be a bit less useful when trying to refer 
people to an url in a different language.
To that end I've created an additional function that first checks for a 
language in the url, then calls the original page function.

urls.py:
...
url(r'^(?P.*)/(?P[-\w\d]+)$', 
'main.views.page_lang',name='page_lang'),
url(r'^(?P[-\w\d]+)$', 'main.views.page',name='page'),
...

views.py
def page_lang(request, language, thepage):
# Set the language
check_for_language(language)
activate(language)
request.session['django_language'] = language

# Next load the page
return page(request, thepage)

def page(request, page):
...

This allows reconstruction of the url but only the current page. If you 
click another page, the language is still changed but the language is not 
added to the url as expected. There are a couple of questions remaining:

- When dealing with multilingual sites, is it better to deal with an url 
with or without the language or both? Without makes the url shorter and 
clean, with makes it more accessible. I'm leaning toward the latter.

- I thought of using language prefix but the prefix argument to 
i18_patterns() is deprecated in v1.8 and I'm not going to add a feature I 
know is changing in the near future. There is a reference to 
django.conf.urls.url() but it's not clear to me on how the proceed with 
this to add the language part in front of my url's.

Thanks for any info regarding this matter,

Regards,
Benedict




-- 
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/ml8oaf%24ukb%241%40ger.gmane.org.
For more options, visit https://groups.google.com/d/optout.