SoFunction
Updated on 2024-11-17

Example of ORM in Django to find out the data whose content is not empty

How to find out the data whose content is not null when manipulating database in django?

from  import Q
 
class Index(VIew):
 def get(self, request):
 userObj = (~Q(asset_id = '')
 return HttpResponse('yes')

The (~Q(nick = '')) in the above code uses the Q function to find out the data where nick is not null, mainly using ~Q

Additional knowledge:Djangoreport an error HINT: Add or change a related_name argument to the definition for '

Unhandled exception in thread started by <function wrapper at 0x05569030>
Traceback (most recent call last):
File “G:\workspace\pycharm\carwin\carwin_env\lib\site-packages\django\utils\”, line 226, in wrapper
fn(*args, **kwargs)
File “G:\workspace\pycharm\carwin\carwin_env\lib\site-packages\django\core\management\commands\”, line 116, in inner_run
(display_num_errors=True)
File “G:\workspace\pycharm\carwin\carwin_env\lib\site-packages\django\core\management\”, line 472, in check
raise SystemCheckError(msg)
: SystemCheckError: System check identified some issues:

ERRORS:

: (fields.E304) Reverse accessor for ‘' *es with reverse accessor for ‘'.

HINT: Add or change a related_name argument to the definition for ‘' or ‘'.

: (fields.E304) Reverse accessor for ‘' *es with reverse accessor for ‘'.

HINT: Add or change a related_name argument to the definition for ‘' or ‘'.

Reason:

Caused by referencing a foreign key table multiple times in a table and not specifying a unique RELEASED_NAME.

Solution:

Take the foreign key in the same table and add a different released_name.

Above this Django in ORM to find out the content of the data is not empty example is all I have shared with you, I hope to give you a reference, and I hope you support me more.