Re: Problem with migrating a fresh db - jango.db.utils.ProgrammingError: column "structure_depth" specified more than once

2019-08-01 Thread Marius Räsener
Hey again,

so to solve this case, a guy from our local user group had the solution, 
which involved of course our custom Field.

changing contribute_to_class to the following changes it. If you have an 
understanding if the two setattr() are needed, please reply :)

def contribute_to_class(self, cls, name, **kwargs):
super().contribute_to_class(cls, name)
depth_name = name + "_depth"

setattr(cls, name, GAEBStructureProperty(name))  # maybe not needed?

if self.dept_field and not cls._meta.abstract:
depth_field = models.PositiveIntegerField(editable=False, 
db_index=True)
cls.add_to_class(depth_name, depth_field)

setattr(
cls,
depth_name,
property(
fget=lambda obj: obj.__dict__[depth_name], fset=lambda obj, 
val: None
),
)  # maybe not needed?

Cheers,
Marius

Am Dienstag, 30. Juli 2019 23:53:00 UTC+2 schrieb Marius Räsener:
>
> Hey everybody,
>
> I hope I can somehow give enough informations but also keep it as little 
> as possible.
>
> situation is:
> - existing migrations deleted to reset migrations (existing migrations 
> seem are broken aswell, for a fresh db)
> - new migrations with makemigrations
> - migrate fails with:
>
>  File 
> "/Users/user/.pyenv/versions/systori-python/lib/python3.6/site-packages/django/db/backends/utils.py",
>  
> line 83, in _execute
> return self.cursor.execute(sql)
> django.db.utils.ProgrammingError: column "structure_depth" specified more 
> than once
>
> Maybe related, this doesn't happen when I run the tests.
>
> And indeed, if I print the sql statement in above mentioned line, I see:
>
> CREATE TABLE "project_project" 
>
>   ("id" serial NOT NULL PRIMARY KEY,
>
>"name" varchar(512) NOT NULL,
>
>"description" text NULL,
>
>"is_template" boolean NOT NULL,
>
>"structure" varchar(64) NOT NULL,
>
>"phase" varchar(50) NOT NULL,
>
>"state" varchar(50) NOT NULL,
>
>"structure_depth" integer NOT NULL CHECK ("structure_depth" >= 0),
>
>"structure_depth" integer NOT NULL CHECK ("structure_depth" >= 0)
>
> )
>
>
> if I print the same when running tests the "structure_depth" isn't present 
> twice.
>
>
> while surfing around with PyCharms nice Debugger I figured that at some 
> point there is an object model, which represents the right model, but 
> model._meta.fields already has the duplicate of "structure_depth". other 
> parts I can find, f.e. something like a ProjectState doesn't have the 
> duplicate "structure_depth". This is all way beyond my current 
> understanding of Django.
>
>
> the generated migrations.CreateModel looks correct, "structure_depth" 
> appears only once.
>
>
> the model is, shortened:
>
>
> class Project(models.Model):
>
> structure = GAEBStructureField(
>
> _("Numbering Structure"), default="01.01.001"
>
> )  # GAEBStructureField adds structure_depth
>
>
> the custom Field is defined as follows:
>
>
> class GAEBStructureField(models.Field):
>
> description = _("Pattern for the GAEB hierarchy code structure.")
>
>
> def __init__(self, *args, **kwargs):
>
> kwargs["max_length"] = 64
>
> super().__init__(*args, **kwargs)
>
>
> def deconstruct(self):
>
> name, path, args, kwargs = super().deconstruct()
>
> del kwargs["max_length"]
>
> return name, path, args, kwargs
>
>
> def contribute_to_class(self, cls, name, **kwargs):
>
> super().contribute_to_class(cls, name)
>
>
> setattr(cls, name, GAEBStructureProperty(name))
>
>
> depth_name = name + "_depth"
>
> depth_field = models.PositiveIntegerField(editable=False, 
> db_index=True)
>
> cls.add_to_class(depth_name, depth_field)
>
> setattr(
>
> cls,
>
> depth_name,
>
> property(
>
> fget=lambda obj: obj.__dict__[depth_name], fset=lambda 
> obj, val: None
>
> ),
>
> )
>
>
> so, I'm kind of proud what I've figured but I'm lost in non-linear land - 
> at least it feels like it. I can't find the point where model._meta.fields 
> actually gets created.
>
>
> so, hopefully maybe someone can point me in the right direction, give some 
> hints or just comment it - all appreciated.
>
>
> this project is open source, so I could aswell just make a branch and 
> upload current state. FYI github.com/systori/systori
>
>
> thx in advance,
>
> Marius
>

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/3a02befb-b18e-488e-954a-bab9dc0af7b0%40googlegroups.com.


Re: select records from a model in another django app

2019-07-31 Thread Marius Räsener
This can have several causes - f.e. did you add the ListView to your 
urls.py? is the import of the models working? (this implies to check your 
folder/module structure)

Am Mittwoch, 31. Juli 2019 10:44:45 UTC+2 schrieb Perceval Maturure:
>
> Hi Marius
> thanks for your input,i did remove the import statements but nothing 
> returned on my template surprisingly in another app the code is working.
>
> #view
>
>
>
> *from django.shortcuts import renderfrom django.views.generic import 
> ListView, DetailView, View, TemplateViewfrom archivesuploads.models import 
> Archivesuploads, Archivetypes, Interestsfrom .models import StaffDetail, 
> PeopleDetail, StudentDetail*
>
>
>
>
>
> *class ArchivesuploadsListView(ListView):#model = Archivesuploads
> context_object_name = 'object_list'queryset = 
> Archivesuploads.objects.all()#[:2] add this to limit the number of 
> publicationstemplate_name = "person.html"*
>
>
> *#template*
>
>
>
>
>
>
>
>
>
>
>
>
>
> *  {% if object_list %}  {% for archiveupload in 
> object_list %}{{ archiveupload.name <http://archiveupload.name> 
> }}   target="_blank"> {{ archiveupload.title }}  ({{ 
> archiveupload.publication_date | date:"Y"}})  {{ 
> archiveupload.general_doi }}{% endfor %}{% 
> else %}  There are no Publications  {% endif %}*
>
> On Tue, Jul 30, 2019 at 11:59 PM Marius Räsener  > wrote:
>
>> Hey Perceval,
>>
>> it seems like you have way too many import statements.
>>
>> something like this should be enough:
>>
>> from django.views.generic import ListView
>> from .models import StaffDetail, PeopleDetail, StudentDetail
>>
>> class ArchivesuploadsListView(ListView):
>> queryset = Archivesuploads.objects.all()#[:2] add this to limit the 
>> number of publications  # <- optional
>> template_name = "person.html" # <- optional
>>
>> model = StaffDetail # <-not optional
>>
>> if you want to use a model from a different app, you need to import only 
>> this specific model:
>>
>> from otherapp.models import OtherModel
>>
>> and then just tell the ListView with model = OtherModel you want to use 
>> it.
>>
>> hope it helps
>>
>> p.s.: please use a different Font! :)
>>
>> Am Dienstag, 30. Juli 2019 20:58:55 UTC+2 schrieb Perceval Maturure:
>>>
>>> thanks for the response just to be more elaborative, here is my import 
>>> code and view code. same code is working in the archivesuploads app but 
>>> when i try to fetch the queryset in the other app it does not return records
>>>
>>> #import code
>>> from django.shortcuts import render
>>> from django.shortcuts import render, redirect
>>> from .models import StaffDetail, PeopleDetail, StudentDetail
>>> from django.contrib import messages
>>> from django.http import HttpResponseRedirect
>>> from django.http import HttpResponse
>>> from django.urls import reverse
>>> from django.utils import timezone # to display date and time as per 
>>> timezone
>>> from django.views.generic import ListView, DetailView, View, TemplateView
>>> from archivesuploads.models import Archivesuploads, Archivetypes, 
>>> Interests
>>>
>>> #view
>>> class ArchivesuploadsListView(ListView):
>>>
>>> context_object_name = 'object_list'
>>> queryset = Archivesuploads.objects.all()#[:2] add this to limit the 
>>> number of publications
>>> template_name = "person.html"
>>>
>>> On Tue, Jul 30, 2019 at 1:54 PM John Bagiliko <
>>> john.b...@aims-senegal.org> wrote:
>>>
>>>> I stand to be corrected
>>>>
>>>> On Tue, Jul 30, 2019, 11:53 AM John Bagiliko <
>>>> john.b...@aims-senegal.org> wrote:
>>>>
>>>>> Import the model from the app of choice and use it as usual.
>>>>>
>>>>> On Tue, Jul 30, 2019, 11:32 AM Nitin Kumar  
>>>>> wrote:
>>>>>
>>>>>> Import another app model. 
>>>>>>
>>>>>> On Tue, 30 Jul, 2019, 4:28 PM Perceval Maturure,  
>>>>>> wrote:
>>>>>>
>>>>>>> i want to display  model data using a class based view from another 
>>>>>>> model in a different app.any idead
>>>>>>>
>>>>>>> -- 
&

Re: select records from a model in another django app

2019-07-30 Thread Marius Räsener
Hey Perceval,

it seems like you have way too many import statements.

something like this should be enough:

from django.views.generic import ListView
from .models import StaffDetail, PeopleDetail, StudentDetail

class ArchivesuploadsListView(ListView):
queryset = Archivesuploads.objects.all()#[:2] add this to limit the 
number of publications  # <- optional
template_name = "person.html" # <- optional

model = StaffDetail # <-not optional

if you want to use a model from a different app, you need to import only 
this specific model:

from otherapp.models import OtherModel

and then just tell the ListView with model = OtherModel you want to use it.

hope it helps

p.s.: please use a different Font! :)

Am Dienstag, 30. Juli 2019 20:58:55 UTC+2 schrieb Perceval Maturure:
>
> thanks for the response just to be more elaborative, here is my import 
> code and view code. same code is working in the archivesuploads app but 
> when i try to fetch the queryset in the other app it does not return records
>
> #import code
> from django.shortcuts import render
> from django.shortcuts import render, redirect
> from .models import StaffDetail, PeopleDetail, StudentDetail
> from django.contrib import messages
> from django.http import HttpResponseRedirect
> from django.http import HttpResponse
> from django.urls import reverse
> from django.utils import timezone # to display date and time as per 
> timezone
> from django.views.generic import ListView, DetailView, View, TemplateView
> from archivesuploads.models import Archivesuploads, Archivetypes, Interests
>
> #view
> class ArchivesuploadsListView(ListView):
>
> context_object_name = 'object_list'
> queryset = Archivesuploads.objects.all()#[:2] add this to limit the 
> number of publications
> template_name = "person.html"
>
> On Tue, Jul 30, 2019 at 1:54 PM John Bagiliko  > wrote:
>
>> I stand to be corrected
>>
>> On Tue, Jul 30, 2019, 11:53 AM John Bagiliko > > wrote:
>>
>>> Import the model from the app of choice and use it as usual.
>>>
>>> On Tue, Jul 30, 2019, 11:32 AM Nitin Kumar >> > wrote:
>>>
 Import another app model. 

 On Tue, 30 Jul, 2019, 4:28 PM Perceval Maturure, >>> > wrote:

> i want to display  model data using a class based view from another 
> model in a different app.any idead
>
> -- 
> 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...@googlegroups.com .
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/django-users/5529da22-0981-43ca-a98a-d13edcc5ba94%40googlegroups.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...@googlegroups.com .
 To view this discussion on the web visit 
 https://groups.google.com/d/msgid/django-users/CAKzNicG9paZfyTWFqMD5hNxwrhT-FH1rKFqxA24oj%3DMprzQZtw%40mail.gmail.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...@googlegroups.com .
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/django-users/CAC26BE218VXdczBfrQD4_CWEf-PyTUML-DgjBoTwdH%3DSmAaNkA%40mail.gmail.com
>>  
>> 
>> .
>>
>
>
> -- 
> *Perceval Maturure*
>
> *083 303 9423*
>

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/1a6af686-3708-4de9-86d8-d106400881ff%40googlegroups.com.


Problem with migrating a fresh db - jango.db.utils.ProgrammingError: column "structure_depth" specified more than once

2019-07-30 Thread Marius Räsener
Hey everybody,

I hope I can somehow give enough informations but also keep it as little as 
possible.

situation is:
- existing migrations deleted to reset migrations (existing migrations seem 
are broken aswell, for a fresh db)
- new migrations with makemigrations
- migrate fails with:

 File 
"/Users/user/.pyenv/versions/systori-python/lib/python3.6/site-packages/django/db/backends/utils.py",
 
line 83, in _execute
return self.cursor.execute(sql)
django.db.utils.ProgrammingError: column "structure_depth" specified more 
than once

Maybe related, this doesn't happen when I run the tests.

And indeed, if I print the sql statement in above mentioned line, I see:

CREATE TABLE "project_project" 

  ("id" serial NOT NULL PRIMARY KEY,

   "name" varchar(512) NOT NULL,

   "description" text NULL,

   "is_template" boolean NOT NULL,

   "structure" varchar(64) NOT NULL,

   "phase" varchar(50) NOT NULL,

   "state" varchar(50) NOT NULL,

   "structure_depth" integer NOT NULL CHECK ("structure_depth" >= 0),

   "structure_depth" integer NOT NULL CHECK ("structure_depth" >= 0)

)


if I print the same when running tests the "structure_depth" isn't present 
twice.


while surfing around with PyCharms nice Debugger I figured that at some 
point there is an object model, which represents the right model, but 
model._meta.fields already has the duplicate of "structure_depth". other 
parts I can find, f.e. something like a ProjectState doesn't have the 
duplicate "structure_depth". This is all way beyond my current 
understanding of Django.


the generated migrations.CreateModel looks correct, "structure_depth" 
appears only once.


the model is, shortened:


class Project(models.Model):

structure = GAEBStructureField(

_("Numbering Structure"), default="01.01.001"

)  # GAEBStructureField adds structure_depth


the custom Field is defined as follows:


class GAEBStructureField(models.Field):

description = _("Pattern for the GAEB hierarchy code structure.")


def __init__(self, *args, **kwargs):

kwargs["max_length"] = 64

super().__init__(*args, **kwargs)


def deconstruct(self):

name, path, args, kwargs = super().deconstruct()

del kwargs["max_length"]

return name, path, args, kwargs


def contribute_to_class(self, cls, name, **kwargs):

super().contribute_to_class(cls, name)


setattr(cls, name, GAEBStructureProperty(name))


depth_name = name + "_depth"

depth_field = models.PositiveIntegerField(editable=False, 
db_index=True)

cls.add_to_class(depth_name, depth_field)

setattr(

cls,

depth_name,

property(

fget=lambda obj: obj.__dict__[depth_name], fset=lambda obj, 
val: None

),

)


so, I'm kind of proud what I've figured but I'm lost in non-linear land - 
at least it feels like it. I can't find the point where model._meta.fields 
actually gets created.


so, hopefully maybe someone can point me in the right direction, give some 
hints or just comment it - all appreciated.


this project is open source, so I could aswell just make a branch and 
upload current state. FYI github.com/systori/systori


thx in advance,

Marius

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/94d6f267-986c-48ee-b141-e91c25ec57da%40googlegroups.com.


Django Channels - core.py error

2018-09-01 Thread Marius Räsener
Hey, my guess is to check redis integration, f.e. like mentioned here at the 
bottom (outside of consumers):
https://channels.readthedocs.io/en/latest/topics/channel_layers.html

next guess, since an unintended lock feels rather basic to me is to make sure 
you‘re still following the virtualenv best practices? No Idea if that’s worth 
mentioning or already clear but to be sure...

Good luck

-- 
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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/075f20c5-3cc1-4a08-9480-62ac020f7ece%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Recursive one-to-many foreign key on the same table

2018-08-09 Thread Marius Räsener
Hey Philip,

while I can't help you with your actual implementation I wanted to link you 
to this presentation abuot the topic, it's worth time spend I think ...

https://www.youtube.com/watch?v=CRxjoklS8v0=7=PLY_che_OEsX3aZo5RttI6Fj2XZ7nTjhBu

recursive models are tricky, especially to query afterwards - your example 
might be not super complicated (yet) but still, I recommend the video...

Marius

Am Donnerstag, 9. August 2018 14:42:13 UTC+2 schrieb Phlip Pretorius:
>
> I want to build a one-to-many recursive foreign key on a table in Django.
>
> The concept is something like this:
>
> Table: staff/person
>
> staff numberSurnameFirstnamesSupervisor
> 4637ZondoJulien
> 859076VanderbildtJohn4637
>
> That is, Julien Zondo is John Vanderbildt's supervisor and to enter the 
> staff number in the supervisor field, it must exist in the staff table.
>
> Each staff member can have only one supervisor but a person can be the 
> supervisor of many staff members.
>
> I have read the documentation at 
> https://docs.djangoproject.com/en/2.1/ref/models/fields/#recursive-relationships
>  
> but i do not get the gist of it
>
> I want to build an index table on three levels where a level 1 index will 
> have no predecessor
> Level 2 indexes must have a level 1 predecessor and a level 3 index must 
> have a level 2 pedecessor.
>
> Can this be done by using recursive relationships or should this be done 
> in a business layer?
>
> Here is part of the definition of the model:
>
> =
> Class DecisionIndex(models.Model):
> """A mechanism to index decision taken by a committee"""
> IndexCode = models.CharField(max_length=6)
> IndexDesc = models.CharField(max_length=80, null=False)
> IndexLevel = models.IntegerField(choices=list(zip(range(1, 4),
>   range(1, 4))),
>  null=False)
> IndexPredecessor = models.ForeignKey('self',
>  on_delete=models.CASCADE,
>  limit_choices_to={'IdexLevel': 
> 1},)
>
> 
>
> I get the following error message:
> no such column: komadm_apps_decisionindex.IndexPredecessor_idno such 
> column: 
>
> Any help will be welcome.
>
> Regards,
>
> Phlip
>

-- 
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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/bc512a99-625d-4ac1-8a2d-0ffd4a5692be%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Django-channels request depending Middleware

2018-05-04 Thread Marius Räsener
Hey everybody,

We are using a Middleware to inject postgresql schemas into queries based on a 
subdomain. You can have a look how it‘s done here:
https://github.com/systori/systori/blob/dev/systori/apps/company/middleware.py

Now, for channels I‘ve noticed that there is no usual request, right?
So, if I‘m connecting a WS it doesn‘t hit the Middleware. 
Are there any guides or docs available or any recommendations how to solve this 
properly for channels?

Thx,
Marius

-- 
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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/6534824B-4E3B-4E39-8DA0-DF807A84CADC%40mehr-handwerk.de.
For more options, visit https://groups.google.com/d/optout.