New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ordering direction #171
Comments
I'm not quite sure what you mean -- can you give me an example as a Django queryset / Python code? If its possible to translate your request into a single queryset, then we should be able to support it. |
When looking up the QuerySet documentation to achieve this, I found out you can add a minus sign before the column names given to |
Ah I misunderstood -- we do support sorting by descending order, simply prefix your field with a I didn't realize that this was not documented in our README, feel free to create a PR to address this. Thanks! |
I sure will, but there's one more thing I'd like to address before updating the README. Here the README says that you can sort by fields of related records as well, but it doesn't seem to work. I traced the problem to this condition which returns |
@Incanus3 can you give me an example? I believe that it is possible to use dot notation to sort through |
Sure. I have two models like this: class GastroGroup(Model):
class Meta:
db_table = 'gastro_groups'
name = CharField(max_length = 64, unique = True)
gastro_type = CharField(max_length = 64)
for_register = RequiredBooleanField()
for_nearby_stock = RequiredBooleanField()
for_main_stock = RequiredBooleanField()
class Recipe(Model):
class Meta:
db_table = 'recipes'
plu = IntegerField()
name = CharField(max_length = 64, unique = True)
type = CharField(max_length = 64) # this should be an enum
amount = DecimalField(max_digits = 12, decimal_places = 3, default = 1)
register_gastro_group = ForeignKey(GastroGroup, null = True, blank = True, related_name = '+')
nearby_stock_gastro_group = ForeignKey(GastroGroup, null = True, blank = True, related_name = '+')
main_stock_gastro_group = ForeignKey(GastroGroup, null = True, blank = True, related_name = '+') and their serializers: GastroGroupSerializer():
id = IntegerField(label='ID', read_only=True)
name = CharField(max_length=64, validators=[<UniqueValidator(queryset=GastroGroup.objects.all())>])
gastro_type = CharField(max_length=64)
for_register = BooleanField()
for_nearby_stock = BooleanField()
for_main_stock = BooleanField()
RecipeSerializer():
id = IntegerField(label='ID', read_only=True)
register_gastro_group = DynamicRelationField('datastore.serializers.GastroGroupSerializer')
nearby_stock_gastro_group = DynamicRelationField('datastore.serializers.GastroGroupSerializer')
main_stock_gastro_group = DynamicRelationField('datastore.serializers.GastroGroupSerializer')
plu = IntegerField(max_value=2147483647, min_value=-2147483648)
name = CharField(max_length=64, validators=[<UniqueValidator(queryset=Recipe.objects.all())>])
type = CharField(max_length=64)
amount = DecimalField(decimal_places=3, max_digits=12, required=False) Now, filtering by nested attributes, e.g. Looking at the code here, this makes sense, since |
You are absolutely right, this implementation does not supported nested fields! It will take a bit of work, but we should be able to tweak To be honest, I'm not sure when we will be able to get to this as we have some other priorities. If you would like to take a stab at it, let me know and I'll hold off on my end. |
If I understand the problem correctly, this should be a simple matter of splitting |
Generally that sounds right. In this case
|
I don't think it should be necessary to build the complete list of all possible (deeply nested) ordering chains. This is working for me. You can also narrow down the list of allowed filters by setting |
👍 that sounds great, I was not suggestion that we should generate a complete list of ordering chains (the default behavior of |
Ok, my solution doesn't work when serializer field names differ from the model field names, I'll try to address that tomorrow. |
I fixed the case where serializer field names differ from model field names. I made it pass through |
The solution looks correct to me, couple comments:
|
Hi, if (not getattr(field, 'write_only', False) and not field.source == '*') The question was, are these still needed? And if so, do we need to check these on every segment of the chain? Also, why do we need to use point 3 - solved (the links point to master version of the file, so if you refresh them, you'll see the updated version) |
Um, I don't want to be obtrusive, but is this receiving any attention? I can have this finished in half an hour if you just answer my last question. |
I believe the check Sorry about the delay in response |
Hi, I'm so sorry, between my last question and your answer I was assigned a high priority ticket from a completely different project and had to work on it since. But the changes should now be ready for a final review. You can check the final changes here. I made it pass through |
@aleontiev could you please look at this and tell me, if there's sth else I need to do (beside rebase, squash and PR) to get this merged? |
Hey guys! I just ran into the same issue and wanted to ask if there is any progress here before I try fixing it myself... |
This should be ready to merge since the end of July. Just ping me when you're ready and I'll rebase and create a PR. @aleontiev |
Hi everyone. I'd just like to ask about the status of this issue. Will @Incanus3's fix be merged in soon? |
Also interested when this will be implemented? |
Also interested in this! I'll try using @Incanus3's branch directly for now. Please merge and push to PyPi though. Thanks! |
@Incanus3 - Would you be willing to open a PR? |
Sure, I was willing to do that from the start. But it will probably take me a few days to rebase (hopefully not much has changed in the concerned part of the codebase), since I've got a lot of other work right now. Should be ready after the weekend though. |
I managed to get your branch installed and working through my setup.py file: setup(
install_requires=[
# 'dynamic-rest==1.7.1',
'dynamic-rest==1.6.8',
],
dependency_links=[
# https://github.com/AltSchool/dynamic-rest/issues/171
'https://github.com/Incanus3/dynamic-rest/archive/feature/ordering-by-related-fields.tar.gz#egg=dynamic-rest-1.6.8'
],
) I noticed at least one regression in functionality I depend on since the branch is currently off of an older version of Dynamic REST, so I'm looking forward to the rebase. Thanks in advanced, @Incanus3! Hopefully we can get @aleontiev to merge it this time too! |
Sorry guys, I've been assigned some high priority work and won't have time for this for at least 2 weeks. |
I rebased and open a merge request! Please review @Incanus3 and @aleontiev! |
Add support for ordering by nested fields #171
That is great news! No problem, it wasn't that hard. I'm sorry I couldn't be of more assistance in the end. I've been quite busy these last few weeks. |
Is this live on the master branch? |
I think this is solved can we close this? |
Hi,
I know this isn't the right place for Q&A, but I haven't found any documented place to ask questions, so I'm asking here. Is there a way to dynamically sort records in descending order, e.g. something like
/clients?sort[]=name.desc&page=2&per_page=5
(this doesn't work obviously). I could sort the records on the client side, but that doesn't cover the pagination case.The text was updated successfully, but these errors were encountered: