Skip to content

Instantly share code, notes, and snippets.

@paltman
Last active April 20, 2020 15:46
Show Gist options
  • Save paltman/7225dbf00202e332bf8f98c4887bf747 to your computer and use it in GitHub Desktop.
Save paltman/7225dbf00202e332bf8f98c4887bf747 to your computer and use it in GitHub Desktop.

Revisions

  1. paltman revised this gist Apr 20, 2020. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions App.vue
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,6 @@
    <template>
    <div class="bookmark-list">
    <button @click="refresh">Refresh</button>
    <div v-for="(bookmark, index) in bookmarks" :key="index">
    <a :href="bookmark.url">{{ bookmark.title }}</a>
    </div>
  2. paltman revised this gist Apr 20, 2020. 1 changed file with 8 additions and 3 deletions.
    11 changes: 8 additions & 3 deletions App.vue
    Original file line number Diff line number Diff line change
    @@ -15,10 +15,15 @@ export {
    bookmarks: [],
    }
    },
    methods: {
    refresh() {
    api.getBookmarks(data => {
    this.bookmarks = data.bookmarks;
    });
    }
    },
    created() {
    api.getBookmarks(data => {
    this.bookmarks = data.bookmarks;
    });
    this.refresh();
    }
    }
    </script>
  3. paltman created this gist Apr 20, 2020.
    24 changes: 24 additions & 0 deletions App.vue
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,24 @@
    <template>
    <div class="bookmark-list">
    <div v-for="(bookmark, index) in bookmarks" :key="index">
    <a :href="bookmark.url">{{ bookmark.title }}</a>
    </div>
    </div>
    </template>

    <script>
    import api from './api';
    export {
    data() {
    return {
    bookmarks: [],
    }
    },
    created() {
    api.getBookmarks(data => {
    this.bookmarks = data.bookmarks;
    });
    }
    }
    </script>
    3 changes: 3 additions & 0 deletions api.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,3 @@
    def bookmarks(request):
    data = [b.data() for b in Bookmark.objects.all()]
    return JSONResponse(data=dict(bookmarks=data))
    6 changes: 6 additions & 0 deletions models.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,6 @@
    class Bookmark(models.Model):
    title = models.CharField(max_length=250)
    url = models.CharField(max_length=500)

    def data(self):
    return dict(title=self.title, url=self.url)