Re: [mezzanine-users] Re: Extra model fields at Mezzanine's derived package ?

2016-11-16 Thread joanbm
Thanks Ryne, for the explanation of MIGRATION_MODULES setting.

I've finally dealt with extension migrations and avoided burden of other 
apps migrations shipping at the same time.

For a reference, brief info which seems to work with Django 1.8+


   1. assign extra model fields in package's *__init__* like mezzanine does 
   # deferred fields assignment
   django.db.models.signals.class_prepared(add_extra_model_fields, weak=
   False)
   
   def add_extra_model_fields(sender,**kwargs):
  ...
  field = django.db.models.(...)
  field.contribute_to_class(,'')
   
   2. hand-written migration of extension's package 
   from __future__ import unicode_literals
   from django.db import migrations, models
   
   # Trick django migration runs for other application
   TARGET_APP = 'shop'
   
   
   class Migration(migrations.Migration):
   # Change to intended application label
   def __init__(self, name, app_label):
   super(Migration, self).__init__(name, TARGET_APP)
   
   dependencies = [
   ('shop', '0007_auto_20150921_2323'),
   ('cartridgex', '0002_productproperties_variation'),
   ]
   
   # Django would consider this migration as 'squashed'
   replaces = (
   ('shop', '0008_productvariation_tax'),
   )
   
   operations = [
  migrations.AddField(
 ...
   
   

-- 
You received this message because you are subscribed to the Google Groups 
"Mezzanine Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to mezzanine-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [mezzanine-users] Re: Extra model fields at Mezzanine's derived package ?

2016-11-15 Thread joanbm


> Without knowing exactly which models you're modifying, I would recommend 
> to avoid field injection in reusable apps. If you're injecting stuff on 
> Page, it might be better to create a custom Page type and distribute 
> that with your package. See: 
>
I extend models which are not designed as swappable as 
cartridge.shop.ProductVariation, ProductOption, CartItem, Orde or 
mezzanine.blog.BlogPost etc.
 

>  
>
If you still want to go with the field injection route, there are a few 
> approaches that I know of: 
>
> - Maintain your own migration history for modified models using Django's 
> MIGRATION_MODULES 
>
> http://mezzanine.readthedocs.io/en/latest/model-customization.html#field-injection-caveats
>  
>
> I'm aware of this option, but it is a dictionary with application name as 
a key, right ? How can I tell Django to look for *cartridge.shop* 
migrations both at original path and my extension package ?

- Add support for "out of app" migrations to Django 
> http://bitofpixels.com/blog/upgrading-to-mezzanine-4/ 
> 
>  
> (see the 
> EXTRA_MODEL_FIELDS section) 
>
> Tried trick django with "out of app" migrations by altering their app 
label in initializer, but getting cyclic errors for ForeignKey fields.
 

> - Create a model with your extra fields and couple it with a OneToOne 
> field. 
>
 Yes, but it would require big code refactoring, loss of logical 
separateness, less effectiveness as whole model loaded even when some parts 
won't be used ...

Anyway thanks for your reply.

I may come with specific migration error if there even exists some solution 
without monkeypatching Django itself.
 

-- 
You received this message because you are subscribed to the Google Groups 
"Mezzanine Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to mezzanine-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[mezzanine-users] Re: Extra model fields at Mezzanine's derived package ?

2016-11-11 Thread joanbm
 Fixed *class_prepared* signal call (due to weak reference to handler) but 
issue with migrations remains.
 

-- 
You received this message because you are subscribed to the Google Groups 
"Mezzanine Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to mezzanine-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[mezzanine-users] Extra model fields at Mezzanine's derived package ?

2016-11-11 Thread joanbm
Hello,

I've built Mezzanine/Cartridge based project with lot of generic code 
suited for other similar projects.
I'd like to separate it in a standalone package - extension and use it as 
other 3rd party Django apps.

There is however a problem. It extends Mezzanine and Cartridge models with 
additional fields by `EXTRA_MODEL_FIELDS` mechanism, but it works AFAIK for 
target project only, in its settings.
I'm looking for some advice how build such extension, without retire to 
subclassing, thus introducing original n+1 query problem.

Played with manual call to `contribute_to_class` new field's method through 
`class_prepared` signal in package's init file, but registered function is 
never called. Also have no idea how write migrations, because Django/South 
couldn't generate them.



-- 
You received this message because you are subscribed to the Google Groups 
"Mezzanine Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to mezzanine-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[mezzanine-users] How create AUTH_PROFILE_MODULE to work at checkout ?

2016-05-04 Thread joanbm
When set *AUTH_PROFILE_MODULE* in *settings.py*, Cartridge should attempt 
retrieve existing profile data and fill matched fields in checkout form.

If not stored in a session or last order, it fetches them from User 
profile. And here are the troubles.

By the cartridge.shop.checkout.initial_order_data 

 function, 
it tries profile model and model from request, in that order, but they are 
in different unrelated types.
*request.user* is of *SimpleLazyObject* and *get_profile_for_user* returns 
normal instance of *django.db.models.Model* descendant. But it latter case 
it never works, because *profile model fields are not callable* and the 
condition won't eval to true.

Any idea what should custom AUTH_PROFILE_MODULE provide to work with 
checkout code ?


-- 
You received this message because you are subscribed to the Google Groups 
"Mezzanine Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to mezzanine-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.