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

  • SEARCH
  • Home
  • 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 838259
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T05:16:33+00:00 2026-05-15T05:16:33+00:00

So I am trying to emulate google app’s status page: http://www.google.com/appsstatus#hl=en but for backups

  • 0

So I am trying to emulate google app’s status page: http://www.google.com/appsstatus#hl=en but for backups for our own servers. Instead of service names on the left it’ll be server names but the dates and hopefully the pagination will be there too. My models look incredibly similar to this:

from django.db import models

STATUS_CHOICES = (
    ('UN', 'Unknown'),
    ('NI', 'No Issue'),
    ('IS', 'Issue'),
    ('NR', 'Not Running'),
)

class Server(models.Model):
    name = models.CharField(max_length=32)

    def __unicode__(self):
        return self.name

class Backup(models.Model):
    server = models.ForeignKey(Server)
    created = models.DateField(auto_now_add=True)
    modified = models.DateTimeField(auto_now=True)
    status = models.CharField(max_length=2, choices=STATUS_CHOICES, default='UN')
    issue = models.TextField(blank=True)

    def __unicode__(self):
        return u'%s: %s' % (self.server, self.get_status_display())

My issue is that I am having a hell of a time displaying the information I need. Everyday a little after midnight a cron job will run and add a row for each server for that day, defaulting on status unknown (UN).

My backups.html:

{% extends "base.html" %}
{% block content %}
<table>
    <tr>
        <th>Name</th>
{% for server in servers %}
        <th>{{ created }}</th>
    </tr>
    <tr>
        <td>{{ server.name }}</td>
        {% for backup in server.backup_set.all %}
        <td>{{ backup.get_status_display }}</td>
        {% endfor %}

    </tr>
{% endfor %}
</table>
{% endblock content %}

This actually works but I do not know how to get the dates to show. Obviously {{ created }} doesn’t do anything but the servers don’t have create dates. Backups do and because it’s a cron job there should only be X number of rows with any particular date (depending on how many servers we are following for that day).

Summary

I want to create a table, X being server names, Y being dates starting at today while all the cells being the status of a backup. The above model and template should hopefully give you an idea what my thought process but I am willing to alter anything. Basically I am create a fancy excel spreadsheet.

  • 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-15T05:16:33+00:00Added an answer on May 15, 2026 at 5:16 am

    I suggest adding a function to get the dates you want to show, that’s independent of a Server instance. Then you can use it both to get the recent backups and to get the dates for the header. In models.py:

    from django.db import models
    import datetime
    
    def recent_dates():
        return [datetime.date.today() - datetime.timedelta(days=days) 
                for days in range(-6, 1)]
    
    class Server(models.Model):
        ...
        def backup_for_date(self, date):
            next_date = date + datetime.timedelta(days=1)
            return self.backup_set.get(created__gte=date, created__lt=next_date)
    
        def recent_backups(self):
            return [self.backup_for_date(date) for date in recent_dates()]
    

    Then, if you use the function in views.py:

    from django.shortcuts import render_to_response
    from myapp.models import Server, recent_dates
    
    def status(request):
        servers = Server.objects.all()
        return render_to_response('status.html', 
            {'dates': recent_dates(), 'servers': servers}
        )
    

    …you can use the recent_dates variable to print the headers in the template:

    {% extends "base.html" %}
    {% block content %}
    <table>
        <tr>
            <th>Name</th>
            {% for date in recent_dates %}
            <th>{{ date }}</th>
            {% endfor %}
        </tr>
        {% for server in servers %}
        <tr>
            <td>{{ server.name }}</td>
            {% for backup in server.recent_backups() %}
            <td>{{ backup.get_status_display }}</td>
            {% endfor %}
        </tr>
        {% endfor %}
    </table>
    {% endblock content %}
    

    Using this method also makes sure the cells don’t get shifted out of position if data is missing. The code I provided will raise an exception in the call to the get() method inside backup_for_date() if data is missing, but backup_for_date() could easily be modified to return None in that case.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to emulate the menu's in http://www.clydeproperty.com/ I want to hover over
I'm trying to emulate the heart transition shown at: http://www.templatemonster.com/flash-templates/31595.html?scr_type=1&hide_flash=0&tab=32 in HTML5 / JS,
I'm getting an error when trying to emulate an YUI Anim sample: <script src=http://yui.yahooapis.com/3.0.0/build/yui/yui-min.js></script>
I am trying to emulate this behavior in java curl -u usrname:password http://somewebsite.com/docs/DOC-2264 I
I'm trying to emulate this effect: http://meyerweb.com/eric/css/edge/complexspiral/demo.html on my blog: http://segment6.blogspot.com/ It works, but
I have a list view on a page and am trying emulate the toggling
I'm trying to emulate the way Google Calendar and Outlook handle time selection where
I'm trying to emulate the twitter model in my Rails 2.3.8 app (ruby 1.8.7)
I'm trying to emulate the animation seen in the default camera app, where a
I'm trying to emulate what growl does with an app that I have. At

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.