Hello dear Django experts! I ask for help in this matter: There is a code:

As I understand it, readonly_fields is not suitable for applying to only one line (record) of the entire class?

See Making queries | Django documentation | Django as a place to start.

No, it’s the other way around. The admin class attribute readonly_fields is only useful when looking at the detail view of an individual instance of a class.

It was exactly this document that I looked at to do what I intended. And even everything worked out, but not for one row, but for the whole table … :woozy_face:
please help me figure it out. I’m not asking for myself, but to help a friend. :pray:

besides, I have little experience and have difficulties with English. I am only learning and sometimes I don’t understand some things …

I understand and respect that. I give you a lot of credit for working through this in your non-native language. (I’ve tried to provide assistance to others here using their native language and google translate - I’m not sure how effective it has been)

So lets try a simpler example. If you’ve got an instance of Articles named an_article, and you want to refer to the string_1 attribute of an_article, how would you access string_1?

I am also grateful to you that you are wasting your time with me and for this I tell you - Thank you very much!

In my case, I will just filter the word I need, since I already wrote it …
I feel that I’m wrong here, but I can’t find the right answer, although I frantically read the documentation that you recommend to me …

q = Articles.objects.filter(an_article__incontains=srting_1)

or like this:
q = Articles.objects.get (???)

I’m not talking about any database references. I’m assuming you already have a variable named an_article.

So, lets say you already have done something like:
an_article = Articles.objects.get(pk=1)

You have this an_article object which is an Articles.

Now you want to print string_1 from this instance of an_article.

print( ??? )

What would you put within that print statement to print string_1 from an_article?

if an_article = Articles.objects.get(pk=1) is print (an_article)

Ok, but what if you just want to print the string_1 field within an_article?

I just didn’t find it anywhere, or rather didn’t understand how it’s done from examples.

Have you worked your way through either the official Django Tutorial or the Django Girls tutorial?

If not, you should. Either one of them are going to help you a lot with understanding how Django works.

I read a lot, but I understood little. I experimented and looked differently in examples and did it.
But here apparently my path in this matter becomes even more complicated …
I will probably have to look for the answer there.
Although there I was already looking.
Thank you very much Ken!
While my knowledge is still not enough … :confused:

Everybody goes through the learning process - and it does take time.

But I strongly encourage that you don’t just read the tutorials. To get the most out of them, you need to work your way through them. That includes typing all the code and examples to help reinforce what you’re reading. (Typing all the code improves comprehension and retention of what you’re reading. It takes longer, but you learn more in the process.)

Thanks for your time!
It’s a pity I just can’t help my friend.

You can. But, you want to be able to do that without making things worse - and to do that, you may need to learn more than what you already know.

I have already been trying to do this for 2 months, but from the documents and examples I can’t figure out what OBJ is equal to in my case?

Answers three times in previous responses - I’m not sure I can be any more explicit than this. If this isn’t clear, then you absolutely need to work your way through the Django Tutorial for you to acquire the necessary background knowledge to understand the answers being provided.

1 Like