Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6725433
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T09:48:23+00:00 2026-05-26T09:48:23+00:00

I have the following Abstract: class A: clientname … logs = models.ManyToManyField(B, blank=True, null=True)

  • 0

I have the following Abstract:

class A:
    clientname ...
    logs = models.ManyToManyField(B, blank=True, null=True)

class B.
    message ...
    timestamp =  models.DateTimeField()

    def save(self, *args, **kwargs):
        self.timestamp = datetime.now()
        super(B, self).save(*args, **kwargs)

Now, if a message is saved I want it to have a timestamp, always. And I do not want to change the many2many relationship. Is this possible? And if It is how would I go about writing it?

UPDATE:

my view

def log(request):
    if request.method == 'POST':
        log, created = B.objects.get_or_create(message=request.POST['message'])
        client = \
            A.objects.get(clientname=request.POST['clientname'])
        client.logs.add(log)
        return HttpResponse(content="OK", mimetype="text/plain", status=200)
    else:
        return HttpResponse(content="Failed", mimetype="text/plain", status=400)

RESOLUTON:
I did it, this is kind of a workaround:

def log(request):
    if request.method == 'POST':
        time = datetime.now()
        log, created = \
            Log.objects.get_or_create(message=request.POST['message'], \
            timestamp=time)
        client = \
            Thinclient.objects.get(hostname=request.POST['clientname'])
        client.logs.add(log)
        return HttpResponse(content="OK", mimetype="text/plain", status=200)
    else:
        return HttpResponse(content="Failed", mimetype="text/plain", status=400)

UPDATE:

No actually that wasn’t what I wanted either because this will create new message instances even if the message is the same

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T09:48:24+00:00Added an answer on May 26, 2026 at 9:48 am

    add save() to the class B

    def save(self, *args, **kwargs):
        self.timestamp = datetime.now()
        super(B, self).save(*args, **kwargs)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following abstract Django models: class Food(models.Model): name = models.CharField(max_length=100) class Meta:
I have the following situation : abstract class X { abstract X someMethod (...)
Lets say I have the following code: abstract class Animal case class Dog(name:String) extends
Lets assume we have the following code: abstract class Base1 { protected int num;
I have the following class: public abstract class AbstractParent { static String method() {
Lets say i have the following c# classes: abstract class a { protected abstract
I'm looking at some Java classes that have the following form: public abstract class
I have the following Model pattern: public abstract class PARENTCLASS {...} public class CHILD_A_CLASS
I have the following classes in my Model: public abstract class Entity : IEntity
Let's say I have defined the following class: public abstract class Event { public

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.