Re: Conditional annotation super slow

2016-01-06 Thread Simon Charette
Hi Mark, I suppose you opened #26045 about the same issue. Are you using PostgreSQL? If it's the case the issue I suppose the issue is fixed in Django 1.9 . Simon

Re: CachedStaticFilesStorage and collectstatic for the very first time

2016-01-08 Thread Simon Charette
Hi Andrzej, CachedStaticFilesStorage requires you run `collectstatic` before deploying your application in production (non-DEBUG) mode. The deployment should look like that: 1) Update your code to the latest version. 2) Run `collectstatic` to cache paths to hashed versions of your assets. 3) Res

Re: CachedStaticFilesStorage and collectstatic for the very first time

2016-01-08 Thread Simon Charette
t; > In step 2. all static files from external application are copied to > STATIC_ROOT which enables me to proceed. This workaround is not very > beautiful nor django-like. Why? Because there is no such behaviour when I > fell back to default StaticFilesStorage. > > Andrzej > &

Re: Django 1.9.1/python3.4 install errors

2016-01-09 Thread Simon Charette
Hi Nicholas, These warnings should be safe to ignore. See 1.9 release notes for more details. Simon Le samedi 9 janvier 2016 16:30:14 UTC-5, Nicholas Geovanis a écrit : > > Hi all - > Re

Re: Compilation Error while installing

2016-01-12 Thread Simon Charette
Hi, These warnings are safe to ignore, please see 1.9 release notes for more details . Simon Le mardi 12 janvier 2016 12:06:43 UTC-5, Kshitij Saraogi a écrit : > > Hello, > > I was install

Re: How do I add permissions in admin for proxy model?

2016-01-15 Thread Simon Charette
is Proxy model is working if the > model is in same app. But if the model is imported from another app it is > not working. Tried Migrate command. But issue is there. can you help me? > > Cheers, > Manimaran > > On Thursday, November 12, 2015 at 12:27:18 AM UTC+5:30, Si

Re: Filter object by calculating duration from start and end time

2016-01-19 Thread Simon Charette
Hi Steve, You can use annotate for this . from datetime import timedelta from django.db.models import DurationField, ExpressionWrapper, F Entry.objects.annotate( duration=ExpressionWrapper( F('

Re: Filter object by calculating duration from start and end time

2016-01-19 Thread Simon Charette
t; Steve > > On Tuesday, 19 January 2016 18:52:06 UTC, Simon Charette wrote: >> >> Hi Steve, >> >> You can use annotate for this >> <https://docs.djangoproject.com/en/1.9/ref/models/expressions/#using-f-with-annotations> >> . >> >> from d

Re: Is there a hook to run an SQL Query at every Postgres session start?

2016-02-03 Thread Simon Charette
Hi Bobby, I'm not sure this is what you are looking for but it looks like `connection_created`[1] signal might do. Cheers, Simon [1] https://docs.djangoproject.com/en/1.9/ref/signals/#connection-created Le mercredi 3 février 2016 12:25:36 UTC-5, Bobby Mozumder a écrit : > > I'm looking to use

Re: __unicode__ rather than __str__ in Part 2 of 'Writing you first Django app"?

2016-02-11 Thread Simon Charette
Hi John, The tutorial is oriented towards Python 3 users where the `str` type is the equivalent of the Python 2 `unicode` hence why defining `__str__` is suggested. You'll notice that all models example suggest decorating model classes with the `python_2_unicode_compatible` decorator if you need

Re: Why Django-User have all perms, even unexistent?

2016-02-21 Thread Simon Charette
This is only the case for superusers have you might have noticed. Le dimanche 21 février 2016 15:26:54 UTC-5, setivo...@gmail.com a écrit : > > Code in ipython > - > > In [51]: from django.contrib.auth.models import User > > In [52]: User.objects.all() > Out

Re: parallel test running throwing pickleError

2016-02-29 Thread Simon Charette
Hi Girish, I think you didn't to install the `tblib` package[1]. Cheers, Simon [1] https://docs.djangoproject.com/en/1.9/ref/django-admin/#cmdoption-test--parallel Le lundi 29 février 2016 12:13:08 UTC-5, girish ramnani a écrit : > > when running the django test in parallel using the runner.py

Re:

2016-02-29 Thread Simon Charette
Hi Aaron, I think this could be related to the version of your PostgreSQL server. Django 1.9 dropped support for PostgreSQL 9.0[1] which doesn't support GROUP BY selected primary keys[2]. Cheers, Simon [1] https://docs.djangoproject.com/en/1.9/releases/1.9/#dropped-support-for-postgresql-9-0 [

Re: more than one field for aggregates? (ArrayAgg, StringAgg)

2016-02-29 Thread Simon Charette
Hi Tomasz, I suppose you could implement `ROW` as a custom expression[1] and use it in your `ArrayAgg` aggregate as follow: from django.contrib.postgres.aggregates import ArrayAgg from django.db.models import Expression class Row(Expression): template = 'ROW(%(expressions)s)' # ... MyM

Re: Renaming fields in values statements django 1.8

2016-03-04 Thread Simon Charette
Hi Jonty, There's a ticket tracking the addition of this feature[1] but it has not been fixed yet. Cheers, Simon [1] https://code.djangoproject.com/ticket/16735 Le vendredi 4 mars 2016 08:09:20 UTC-5, Jonty Needham a écrit : > > Is there a way to do it? I've seen the method with extra, but tha

Re: Renaming fields in values statements django 1.8

2016-03-04 Thread Simon Charette
Hi Jonty, There's a ticket tracking the addition of this feature[1] but it has not been fixed yet. Cheers, Simon [1] https://code.djangoproject.com/ticket/16735 Le vendredi 4 mars 2016 08:09:20 UTC-5, Jonty Needham a écrit : > > Is there a way to do it? I've seen the method with extra, but tha

Re: more than one field for aggregates? (ArrayAgg, StringAgg)

2016-03-04 Thread Simon Charette
t; works well. > > Best wishes > Tomasz > > > W dniu wtorek, 1 marca 2016 03:52:58 UTC+1 użytkownik Simon Charette > napisał: >> >> Hi Tomasz, >> >> I suppose you could implement `ROW` as a custom expression[1] and use it >> in >> your

Re: more than one field for aggregates? (ArrayAgg, StringAgg)

2016-03-04 Thread Simon Charette
-13T11:41:08.40319'} > ], > 'birthday': None, > 'ins': [ > {u'date': u'2013-11-16T15:00:00', u'number': 1}, > {u'date': u'2013-12-09T10:00:00', u'number': 2}, > {u'dat

Re: more than one field for aggregates? (ArrayAgg, StringAgg)

2016-03-04 Thread Simon Charette
ber')], output_field=CharField() ) ), examinations=JsonAgg( JsonBuildObject( [F('wynikbadania__date_entered')], output_field=CharField() ) ), ).distinct('life_number', 'inseminacja__id', 'wynikbadania__id'

Re: more than one field for aggregates? (ArrayAgg, StringAgg)

2016-03-06 Thread Simon Charette
nct(fields) is not implemented. > > This happens on both 1.9.x branch and 1.10.0.alpha. > > Best wishes, > Tomasz > > > W dniu piątek, 4 marca 2016 22:41:31 UTC+1 użytkownik Simon Charette > napisał: >> >> In order to make sure the bug doesn't lie in your e

Re: addField ForeignKey during migrations create unusable constraint name

2016-03-09 Thread Simon Charette
Hi Gromish, >From looking at you models `db_table` options it looks like you are using a work around to use a table defined in a non default schema (cartography). Django doesn't officially support custom schema yet[1] but there's an ongoing effort to get basic support merged in Django 1.10[2] th

Re: Odd behaviour of DjangoJSONSerializer when serializing datetimes with/without microseconds

2016-03-10 Thread Simon Charette
Hi Rob, The fact DjangoJSONEncoder strips microseconds is definitely a bug that should be reported: > e.default(datetime.datetime(year=2016, month=1, day=1, hour=1, minute=1, second=1, microsecond=123456)) > '2016-01-01T01:01:01.123' I think always including the microseconds could make sense b

Re: Odd behaviour of DjangoJSONSerializer when serializing datetimes with/without microseconds

2016-03-10 Thread Simon Charette
ars 2016 12:12:25 UTC-5, Simon Charette a écrit : > > Hi Rob, > > The fact DjangoJSONEncoder strips microseconds is definitely a bug that > should > be reported: > > > e.default(datetime.datetime(year=2016, month=1, day=1, hour=1, minute=1, > second=1, microsecond=1234

Re: POSSIBLE BUG: using Coalesce() with __in=[]

2016-03-30 Thread Simon Charette
Hi Ryan, I think this should be considered a bug. >From what I understand the ORM simply doesn't perform any query in this case as the `pk__in` lookup cannot match any `OrderItem` and result in an `EmptyResultSet` exception[1]. This exception is caught in the `Query.get_aggregation()` method whe

Re: run python function in output of annotated query

2016-03-31 Thread Simon Charette
Hi Fábio, Since the deprecation of `SubfieldBase`[1] you must implement a `from_db_value()`[2] method to convert the value as returned by the database to the correct Python object. Out of curiosity, is there a reason you are doing this the model level? It looks like something that belongs to the

Re: Request works with sqlite not with Postgres

2016-04-03 Thread Simon Charette
Hi Tazo, The default `output_field` of the `Avg` aggregate is a `FloatField`[1] hence the error raised here. In the case of SQLite, `DurationField`s are stored as large integers of microseconds[2] and the result returned by the database is already a float making `float(value)` a no-op in `convert_

Re: Request works with sqlite not with Postgres

2016-04-04 Thread Simon Charette
écrit : > > Without your help, I would not get the solution. Maybe the doc ( > https://docs.djangoproject.com/en/1.9/ref/models/querysets/#avg) should > be more precise about this case. > Merci beaucoup > > > Le lundi 4 avril 2016 05:35:14 UTC+2, Simon Charette a écrit : >

Re: Issue with Django Password Normalization

2016-04-20 Thread Simon Charette
Hi Arun, I'm not sure this is what you are referring to but Django 1.9 ships with password validation[1] which can be configured to: 1. Prevent field similarity (e.g. password == username) 2. Enforce minimum password length 3. Prevent usage of common password (e.g. "password") 4. Enf

Re: Aggregation issue

2018-06-20 Thread Simon Charette
Hello Gallusz, This is probably caused by the `Financial.Meta.ordering` that you didn't include in your snippet. I assume it's currently defined as ('name', 'financial_year')? In order to get rid of it you'll want to clear it up using an empty call to order_by(): Financial.objects.order_by().

Re: Django Postgres Intermediary doesn't set ON DELETE CASCADE

2018-06-25 Thread Simon Charette
Hey James, Just to add to what was already said there's a ticket tracking the addition of database level foreign constraints.[0] Cheers, Simon [0] https://code.djangoproject.com/ticket/21961 Le samedi 23 juin 2018 09:56:23 UTC-4, Tomasz Knapik a écrit : > > If you search about it on the Intern

Re: Optimizing Prefetch for Postgres IN Limit

2018-07-27 Thread Simon Charette
There's two open tickets to work around this issue. https://code.djangoproject.com/ticket/25464 which allows passing queryset override to be used for retrieval and another one that I can't currently find that allows specifying that a subquery should be used instead of a an IN clause. Simon L

Re: Django Nested Query with Aggregate.Sum()

2018-09-06 Thread Simon Charette
Hello there, You should be able to achieve what you're after by using annotations[0]. In your case you'll want to declare your Event and Reservation relationship explicitly by using a ForeignKey class Event(models.Model): ... seating = models.PositiveIntegerField(default=0) class Reser

Re: Django Nested Query with Aggregate.Sum()

2018-09-07 Thread Simon Charette
event_time|date:"g:i A" }} > {{i.event_type|title}} - > {{i.title|title}} > Purchase Reservation ${{i.price}} Seats > Remaining ### VARIABLE HERE ### >{{ i.description|safe}} > > > > > > > > > > > >

Re: Possible bug in makemigrations

2018-09-12 Thread Simon Charette
Hello Michèl, I'm pretty sure you hit #28862[0] which should be fixed in Django 2.2. Here's the PR resolving it if you're curious about it[1]. Cheers, [0] https://code.djangoproject.com/ticket/28862 [1] https://github.com/django/django/pull/10178 Le mercredi 12 septembre 2018 06:29:30 UTC-4, M

Re: Chaining Q objects

2018-09-19 Thread Simon Charette
Hey Mike, Please provide the full traceback. Also, since all your conditions are ANDed you could use a dict to build filter() kwargs instead of Q() objects. Cheers, Simon Le mercredi 19 septembre 2018 10:36:13 UTC-4, Matthew Pava a écrit : > > I’m not entirely sure if the error is from your Q

Re: AnonymousUser.is_authenticated woes

2018-10-11 Thread Simon Charette
Are you sure you are using Django 1.11? What does ./run.sh manage --version yields? User/AnonymousUser was made a property in Django 2.0+ which I assume your version of Django CMS is not compatible with. Best, Simon Le jeudi 11 octobre 2018 14:26:27 UTC-4, Stefan Bethke a écrit : > > First tim

Re: AnonymousUser.is_authenticated woes

2018-10-11 Thread Simon Charette
://github.com/django/django/blob/66ac7a129a70a225adc263602bcf7f5750698e8d/django/contrib/auth/models.py#L428-L433 Which is why I suspect you have Django 2.0+ installed. Cheers, Simon Le jeudi 11 octobre 2018 14:58:33 UTC-4, Simon Charette a écrit : > > Are you sure you are using Django 1.11? > &g

Re: Is assertIs being misused in Tutorial Part 5?

2018-10-25 Thread Simon Charette
The reason why assertIs is used instead of assertFalse is that the latter actually tests for falsy values and can sometimes hide bugs. For example, assertFalse(0) and assertFalse(None) will pass and assertTrue(42) will as well. If you're testing a method that is supposed to return a boolean val

Re: race condition on post multiple files to the same folder

2018-11-01 Thread Simon Charette
Hello there, I think you just hit #29890[0], a bug present in Django in 2.0+ and fixed in Django 2.1.3 which should be released today[1]. Simply updating to 2.1.3 when it's released should address your issue. Cheers, Simon [0] https://code.djangoproject.com/ticket/29890 [1] https://docs.django

Re: Migrations - moving model between apps

2018-11-15 Thread Simon Charette
Hello Matthew, I'm going to assume no foreign keys are pointing to the model "Foo" you are trying to move from the app "old" to "new". If it's the case then simply repoint them and run makemigrations once the following steps are completed. You could wrap the generated AlterField in SeparateDataba

Re: Max function and grouping with Oracle

2018-11-27 Thread Simon Charette
Dan, The root of the issue here is that you query is asking to retrieve all fields from the Parent table and perform an aggregation on the JOIN'ed child table. That results in the following query SELECT parent.*, MAX(child.updated_timestamp) FROM parent JOIN child ON (child.parent_id = parent.i

Re: Update of issue (Trac) rejected (SPAM ...)

2018-11-29 Thread Simon Charette
>From that point you should post to the developer mailing list as it's reaching more people than the ticket tracker[0]. That should give the opportunity to more people to chime in and provide feedback. Thanks for tackling this issue by the way, this sure is a source a confusion for a lot of Dj

Re: Annotate giving back individual queries rather than results

2018-12-02 Thread Simon Charette
Hey there, I just wanted to clarify that the behavior of including the Meta.ordering fields in aggregation grouping been around for a while and Django 2.2 deprecates it to deal with the exact type of confusion you experienced here. Best, Simon Le dimanche 2 décembre 2018 08:51:17 UTC-5, Coder Du

Re: Unable to do the initial migrations with django-2.1.3 and "mysql 5.5.62-0+deb8u1 (Debian)"

2018-12-02 Thread Simon Charette
Hello there, Django 2.1 dropped support for MySQL 5.5[0] as the end of upstream support is December 2018. You'll have to update to a more recent version to use Django 2.1+. Cheers, Simon [0] https://docs.djangoproject.com/en/2.1/releases/2.1/#dropped-support-for-mysql-5-5 Le dimanche 2 décemb

Re: Problmes

2018-12-03 Thread Simon Charette
Hello David, The current latest version of the Django 1.11 serie doesn't support Python 3.7[0] but 1.11.17, which is still unreleased[1], should per popular demand[2]. Until 1.11.17 is released I'd advise you either stick to Python 3.6 or upgrade to Django 2.0+. Cheers, Simon [0] https://pypi

Re: Use an aggregation function's filter with aggregate of a value from an annotation with a subquery

2018-12-05 Thread Simon Charette
Hello Daniel, It's hard to tell was causes the exception without digging a bit more but based on your mention of multiple sums I assume you are trying to work around the cross join of multiple table annotations? I understand you simplified your query but from what I can see right now it can be ex

Re: Order of migration dependencies when running makemigrations from scratch

2018-12-07 Thread Simon Charette
Hello Dakota, Migration.dependencies should really have been defined as a set from the start as Django doesn't care about their order anyway. I unfortunately cannot provide a work around but I suggest you submit an improvement/cleanup ticket to make the order deterministic. It should be a simple

Re: Poor Performance for Form Rendering In Django 1.11

2018-12-07 Thread Simon Charette
Hello John, Did you try switching to the Jinja2 form renderer[0] to see if it helps? I've not tried it myself but I heard it makes a significant difference. Cheers, Simon [0] https://docs.djangoproject.com/en/2.1/ref/forms/renderers/#jinja2 Le vendredi 7 décembre 2018 08:30:48 UTC-5, John a éc

Re: Order of migration dependencies when running makemigrations from scratch

2018-12-09 Thread Simon Charette
appear before auth's or should that be sorted out by a different mechanism? > > Thanks, > > Dakota > > On Friday, December 7, 2018 at 7:42:09 AM UTC-5, Simon Charette wrote: >> >> Hello Dakota, >> >> Migration.dependencies should really have been defined as a s

Re: Using reflection with Django models to determine module containing the choices?

2018-12-10 Thread Simon Charette
Given choices are defined at the module level I guess you could iterate over objects defined in each `sys.modules` (or the ones likely to define choices) and use the `is` operator to compare all of them to the field choices. This will perform badly and shouldn't be used for anything else than one

Re: python manage.py migrate failed

2018-12-13 Thread Simon Charette
It looks like you configured your CMS_CACHE_DURATIONS setting as an integer instead of a dict with a 'content' key pointing to an integer[0]. In other words you did CMS_CACHE_DURATIONS = 42 Instead of CMS_CACHE_DURATIONS = {'content': 42} Cheers, Simon [0] http://docs.django-cms.org/en/lates

Re: MySQL accepts 0 for a primary key but Django does not

2018-12-28 Thread Simon Charette
Hello Derek, There's no setting but this is controlled by the allows_auto_pk_0 feature flag [0]. Database feature are set to the default database configurations so Django can minimized the number of introspection queries required to work appropriately each time a connection is opened. In order

Re: MySQL accepts 0 for a primary key but Django does not

2018-12-30 Thread Simon Charette
.virtualenvs/s2s/local/lib/python2.7/site-packages/django/db/__init__.py", > > line 34, in __getattr__ > return getattr(connections[DEFAULT_DB_ALIAS], item) > File > "/home/gamesbook/.virtualenvs/s2s/local/lib/python2.7/site-packages/django/db/utils.py", >

Re: Django ORM queryset substring on a column

2019-01-04 Thread Simon Charette
You can use a Func expression for this purpose[0] Employee.objects.annotate( emp_number_suffix=Func('emp_number', Value('-'), -1, function='substring_index'), ).filter( emp_number_suffix='111', ).values('emp_number') Cheers, Simon [0] https://docs.djangoproject.com/en/2.1/ref/models/ex

Re: select_for_update + select_related issue

2020-09-26 Thread Simon Charette
I don't think your issue has anything to do with proxy models. You'll get the exact same error if your use Parent.objects instead of Child.objects as both will generate the same SQL: SELECT * FROM parent LEFT JOIN foreign ON parent.foreign_id = foreign.id FOR UPDATE OF parent In this case "pare

Re: Django Mysql Bulk_Create Ids

2020-09-28 Thread Simon Charette
Unfortunately MySQL doesn't support an equivalent of the RETURNING clause on PostgreSQL/Oracle. In other words MySQL only allows to retrieve an inserted row auto id one at a time through its non-standard LAST_INSERT_ID function. That prevents any attempts at inserting multiple rows and retrievi

Re: Replicating complex query with two dense_rank() functions using ORM

2020-11-04 Thread Simon Charette
This is unfortunately not possible to do through the ORM right now due to lack of support for filtering against window expressions[0] Until this ticket is solved you'll have to rely on raw SQL. Cheers, Simon [0] ticket https://code.djangoproject.com/ticket/28333 Le mercredi 4 novembre 2020 à 1

Re: Questions about code coverage.

2020-11-09 Thread Simon Charette
Hello Chris, > It looks like the gis files aren't covered. Is there any way to run tests and coverage on this code? The tests for these files won't be run unless you run the suite with a GIS enabled database backend. We do it on CI (https://djangoci.com/view/%C2%ADCoverage/) but you can do th

Re: Filtering OR-combined queries

2021-05-03 Thread Simon Charette
Hello Shaheed, I didn't look at your issue into details but since it involves exclude, subqueries, an queryset combination and only manifests itself on Django 3.2 I wouldn't be surprised if it was related to some regressions in this area that are fixed in Django 3.2.1 which is meant to be relea

Re: MODEL CONSTRAINT (based on two dates)

2021-06-30 Thread Simon Charette
Short answer is that you can't; constraints cannot spans across JOINs. You might be able to use database triggers to emulate though. Le lundi 28 juin 2021 à 08:08:27 UTC-4, ngal...@gmail.com a écrit : > I have two models like this > > How can I make models constraint based on the dates as shows

Re: counting the same words within a song added by a user using Django

2021-07-05 Thread Simon Charette
If you're using a PostgreSQL you might want to look at using a tsvector column instead which will ignore stop words (the, or, of, ...) and map lexemes to their number of occurrence and position in the lyrics[0]. Assuming you were to index this column you'd be able to efficiently query it for ex

Re: NotImplemented error combining distinct with annotate

2019-07-21 Thread Simon Charette
Assuming you have a model definition `Salesperson` you could use Salesperson.object.annotate( sales_amount=Sum('sales__sales_amount'), ) But given you mentioned 'salesperson' is a text field you can do persons = Sales.objects.values('salesperson').annotate( sum_sales_amount=Sum('sales_am

Re: What's the best way to update multiple entries in a database based on key/value pairs

2019-07-23 Thread Simon Charette
Hello Don, If you're on Django 2.2+ you should use bulk_update for this purpose[0] TestThing.objects.bulk_update(( TestThing(id=id, value=new_value) for id, value in new_values.items() ), ['value']) Under the hood it performs a SQL query of the form UPDATE ... SET value = (CASE WHEN id=

Re: What's the best way to find the number of database accesses being done?

2019-07-23 Thread Simon Charette
Hello Don, Django logs all database queries to the django.db.backends logger. It is not redirected to STDOUT when using the default settings.LOGGING configuration but you can enable it yourself[0]. If you wan to assert against a fixed number of queries you can use the assertNumQueries context man

Re: Recreating SQL query in ORM

2019-07-31 Thread Simon Charette
Hello, assuming you have a FullMatch model mapped to your FullMatches table the following should do. FullMatch.objects.filter( job_id=job_id, ).values( seq=Concat('loading_code', ...), ids=Concat('loading_id', ), ).annotate( total=Count('*'), ).order_by('-total') Using .value

Re: Duplicated django_content_type Query

2019-08-16 Thread Simon Charette
Hello there, These queries should be cached by ContentTypeManager[0] so something must be broken in your Django install or monkey patching this method. Simon [0] https://github.com/django/django/blob/7da6a28a447dc0db2a2c6ef31894094eb968f408/django/contrib/contenttypes/models.py#L34-L44 Le ven

Re: Aggregating the results of a .union query without using .raw, is it possible?

2019-08-19 Thread Simon Charette
I'm afraid the ORM doesn't support aggregation over unions yet else I would have expected the following to work. objects = Model.objects querysets = ( objects.filter(city=city).values( 'date', weighted_car_crashes=F('car_crashes') * weight ) for city, weight in weights ) union = it

Re: Error: Not able to create table using models (Backend mysql)

2019-09-03 Thread Simon Charette
Django 2.0 only supports MySQL 5.5+. I suspect you're getting a syntax error when Django tries to create a table mapping a model with a DateTimeField since it resolves to DATETIME(6) which is not supported on MySQL < 5.5. Cheers, Simon Le mardi 3 septembre 2019 09:58:19 UTC-4, johnsi rani a éc

Re: MultipleObjectsReturned: get() returned more than one Site -- it returned 2!

2019-09-05 Thread Simon Charette
It's hard to tell what's wrong from the limited context you provided but whatever code is in django_sites_extensions is highly suspicious. Best, Simon Le jeudi 5 septembre 2019 18:02:49 UTC-4, gh a écrit : > > Traceback (most recent call last): >File > "/edx/app/edxapp/venvs/edxapp/local/li

Re: Django Foreign Object

2019-09-26 Thread Simon Charette
This error comes from ForeignObject.resolve_related_fields[0]. If you are using ForeignObject directly you have an incompatible from_fields and to_fields definition. It's hard to debug further without the full traceback. Cheer, Simon [0] https://github.com/django/django/blob/4122d9d3f1983eea61

Re: QuerySet not iterable

2019-10-08 Thread Simon Charette
Hello there, >From looking at your code (super() calls) it seems like your are using Python 2. We've seen similar reports about stdlib functions hiding system level exceptions instead of surfacing them[0] so that might it. It's hard to tell without the full traceback though. Best, Simon [0]

Re: django 2.0 to django 2.2 migration

2019-10-17 Thread Simon Charette
This was tracked in https://code.djangoproject.com/ticket/30673 and fixed and 2.2.5[0] Cheers, Simon [0] https://github.com/django/django/commit/1265a26b2fa3cbd73a2bccd91b700268bc28bc07 Le jeudi 17 octobre 2019 10:31:50 UTC-4, Sijoy Chirayath a écrit : > > I am changing one of my application f

Re: Performing a query returns an error

2019-11-13 Thread Simon Charette
Hello Patrick, >From what I understand you are relying on unmanaged (Meta.managed=False) models to use the ORM to query an externally managed database. The part you missed here is that the ORM maps ForeignKey fields to database columns with a "_id" suffix by default. In your case that means it

Re: Django 2.2: how to use to a field "from a foreign model", in a CheckConstraint: ?

2019-11-14 Thread Simon Charette
Hello there, I guess your example is not the best since this check could be defined on Author.Meta.constraints directly but if you wanted to define such a check on Book anyway you'll have to define a function and refer to it in the check constraint using Func. Using RunSQL in your migrations R

Re: Django GIS query on annotated spatial field

2019-11-14 Thread Simon Charette
Hello Bill, Could you give us more details about which version of Django you are using? There was a few Django bugs related to as_sql returning Union[list, tuple] as params that were fixed in recent release but this one might not have been caught yet. Cheers, Simon Le jeudi 14 novembre 2019 09

Re: Django 2.2: how to use to a field "from a foreign model", in a CheckConstraint: ?

2019-11-14 Thread Simon Charette
For the record I haven' tested the above myself. It might only work on Django 3.0+ and require you to pass `output_field=BooleanField()` to Func. Le jeudi 14 novembre 2019 09:46:48 UTC-5, Simon Charette a écrit : > > Hello there, > > I guess your example is not the best since

Re: Django 2.2: how to use to a field "from a foreign model", in a CheckConstraint: ?

2019-11-14 Thread Simon Charette
So this happened not to be supported in Django 3.0 either. But https://github.com/django/django/pull/12067 should add support for it. Le jeudi 14 novembre 2019 15:50:34 UTC-5, Simon Charette a écrit : > > For the record I haven' tested the above myself. > > It might only work o

Re: Django GIS query on annotated spatial field

2019-11-15 Thread Simon Charette
> > On Thu, 14 Nov 2019 at 16:41, Simon Charette > wrote: > >> Hello Bill, >> >> Could you give us more details about which version of Django you are >> using? >> >> There was a few Django bugs related to as_sql returning Union[list, >> tup

Re: Conditional Order By

2019-11-15 Thread Simon Charette
Hello there, You'll want to use Coalesce[0] for this purpose. Model1.objects.order_by(Coalesce('effectual_rating', 'rating').desc()) Cheers, Simon [0] https://docs.djangoproject.com/en/2.2/ref/models/database-functions/#coalesce Le vendredi 15 novembre 2019 13:32:46 UTC-5, Kev H a écrit : > >

Re: Django GIS query on annotated spatial field

2019-11-18 Thread Simon Charette
t; Kind regards, > Bill > > On Fri, 15 Nov 2019 at 17:19, Simon Charette > wrote: > >> Can you reproduce with Django 2.2.7 (releases November 4th, 2019) >> >> Le vendredi 15 novembre 2019 06:04:32 UTC-5, Bill Bouzas a écrit : >>> >>> Good morning Simon

Re: pip install Django==3.0

2019-12-02 Thread Simon Charette
Dear Uri, > When I use pip to install a package, does it depend on the version of Python I'm using? Yes, it does. > I noticed that Django 3.0 doesn't support Python 3.5. But why does pip fail? Pip will respect the supported version metadata of the package. There's no package available for th

Re: Influencing order of internal migration operations

2019-12-11 Thread Simon Charette
Hello Rich, Unfortunately the migration framework is not smart enough to resolve this kind of dependency. The order of operation/migrations of the makemigrations is generated by the autodetector which hardcodes most of its logic. I would have assumed that constraints were generated _after_ un

Re: FieldError at / Django models how to reslove this issue....

2019-12-19 Thread Simon Charette
You are missing an underscore here. It should be published_date__lte and not published_date_lte. Cheers, Simon Le jeudi 19 décembre 2019 11:40:05 UTC-5, MEGA NATHAN a écrit : > > Hi all. > > Cannot resolve keyword 'published_date_lte' into field. Choices are: author, > author_id, comments, crea

Re: Prefetching returning empty values for some object

2019-12-30 Thread Simon Charette
I suspect your usage of `distinct('path')` is causing issues during prefetching here as it will prevent different File with the same .path from being prefetched for two different folder objects. You likely want to use `distinct('path', 'folder')` here instead where 'folder' might have a differe

Re: UniqueConstraint rises fields.E310 error because of issue with backward compatibility with unique_together

2020-01-20 Thread Simon Charette
Hello Pavel, This is likely a bug because UniqueConstraint was only recently introduced. Please file a bug report about it. In the mean time you can add this check to your SILENCED_SYSTEM_CHECKS setting to silence it. Best, Simon Le lundi 20 janvier 2020 07:21:26 UTC-5, Pavel Garkin a écrit :

Re: Case-insensitve unique = True

2020-01-23 Thread Simon Charette
If you are using PostgreSQL I'd suggest using a CIText field[0] with a unique constraint[1]. If you are *not* using PostgreSQL your best choice is likely to emulate the upcoming expression[3] support for UniqueConstraint(Lower('field')) by using a RunSQL operation that performs the appropriate DD

Re: How to express `foo = (bar < quox)` as a constraint

2020-01-27 Thread Simon Charette
Did you try class Item(Model): price = DecimalField() full_price = DecimalField() is_on_sale = BooleanField() class Meta: constraints = [ CheckConstraint(check=Q(is_on_sale=Q(price__lt=F('full_price' ] I haven't tried it myself but I would expect

Re: How to express `foo = (bar < quox)` as a constraint

2020-01-27 Thread Simon Charette
which a `models.F` is closest to, however using a > `models.F` relation there also doesn't work (see my response to Stephen's > suggestion). > > Thanks, > Peter > > On Monday, 27 January 2020 18:23:28 UTC, Simon Charette wrote: >> >> Did you tr

Re: Model uniqueness constraint with date extraction

2020-02-18 Thread Simon Charette
Hello Thierry, Django doesn't support support constraints on lookups/expressions but there's ungoing work to do so[0]. In the mean time you'll have to rely on a `RunSQL` operation in your migrations to create the constraint. Cheers, Simon [0] https://code.djangoproject.com/ticket/30916 Le m

Re: How to store a boolean expression (parse tree) in a model?

2020-02-18 Thread Simon Charette
I suggest you have a look at the "Trees and Graph" section of the Django Packages website[0]. I've personally used MPTT and Treebeard in the past without too much trouble. You could also a field able to store composite data structures such as JSONField or even a dedicated PostgreSQL type[1] to eff

Re: Django queryset result and mysql query are wrong after updating from 3.0.2 to 3.0.3

2020-02-19 Thread Simon Charette
Hello Ricardo, This could be a regression caused by a patch addressing a regression in 3.0.3[0]. Did you also notice this behaviour on Django 2.2.x or was this project started from Django 3.0? >From what I can see though I find it strange that the ExpressionWrapper of end_total_time have an o

Re: How to store a boolean expression (parse tree) in a model?

2020-02-19 Thread Simon Charette
AND/OR but the child > should not > > > On Tuesday, February 18, 2020 at 11:30:40 PM UTC-5, Simon Charette wrote: >> >> I suggest you have a look at the "Trees and Graph" section of the >> Django Packages website[0]. I've personally used MPTT and Treebe

Re: Django queryset result and mysql query are wrong after updating from 3.0.2 to 3.0.3

2020-02-19 Thread Simon Charette
Hello Ricardo, I suggest you follow these docs to submit your bug report and link to this thread. https://docs.djangoproject.com/en/3.0/internals/contributing/bugs-and-features/#reporting-bugs I'd mention that the issue is also present if you use `output_field=DurationField` as BigIntegerField

<    1   2   3